Android 应用退出的几种方法
16lz
2021-01-23
1、杀进程
android.os.Process.killProcess(android.os.Process.myPid());
2、系统退出
System.exit(0);
3、activity管理
ActivityManager activityManager = (ActivityManager) TestLogout.this .getSystemService(Context.ACTIVITY_SERVICE);
activityManager.killBackgroundProcesses(getPackageName());
4、清除栈
Intent intent = new Intent();
intent.setClass(Logout.this, Logout.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("flag", 1);
startActivity(intent);
5、显示桌面
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
还可以建立Activity列表,在每个Activity创建的时候加入列表;在退出时,遍历列表,逐一activity.finish()。
以上几种方法可以组合使用,达到最终需要的效果。
更多相关文章
- Android 列表之分组ListView
- android dpi换算以及常用分辨率列表
- Android 自定义分享列表ACTION_SEND
- Android | activity之间传递列表,以listview显示
- android最近任务列表,删除某个应用操作
- Android 的res/values/colors自定义颜色列表和注释表及布局文件
- 【Android】ExpandableListView二级列表使用介绍
- android2.3 api demo 学习系列(1)--apidemo主列表的实现