在Android中,Activity有个栈,一个Activity结束掉,会回到上一个Activity,并不是退出应用程序。 Android中,退出应用程序的方式: 1.通过pid int pid = android.os.Process.myPid(); //获取当前应用程序的PID android.os.Process.killProcess(pid); //杀死当前进程 这种方法退出应用,是会保留某些后进程,例如:Service,Notifications等。 2.通过ActivityManager ActivityManager manager = (ActivityManager)context.getSystemService(ACTIVITY_SERVICE); //获取应用程序管理器 manager.killBackgroundProcesses(getPackageName()); //强制结束当前应用程序 这种方式退出应用,会结束本应用程序的一切活动,因为本方法会根据应用程序的包名杀死所有进程包括Activity,Service,Notifications等。