Android应用退出代码各种方式
2015-08-22 08:48
399 查看
1. 点击按钮最小化app返回到home
2. 修改上面代码,添加Intent.FLAG_ACTIVITY_CLEAN_TOP标记
3. 使用标准退出代码System.exit(0)
4. 使用android.os.Process
目前为止,就懂得这么多,就这样先
//并不会退出app,只是最小化 findViewById(R.id.button3).setOnClickListener(new OnClickListener(){ public void onClick(View v){ Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); startActivity(intent); } });
2. 修改上面代码,添加Intent.FLAG_ACTIVITY_CLEAN_TOP标记
//结果一样,没有完全退出app,后台还有其进程在运行 findViewById(R.id.button3).setOnClickListener(new OnClickListener(){ public void onClick(View v){ Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAN_TOP); startActivity(intent); } });
3. 使用标准退出代码System.exit(0)
//不过退出方式粗暴,退出的动画不是很美,但不过后台的进程还是被终结了 findViewById(R.id.button3).setOnClickListener(new OnClickListener(){ public void onClick(View v){ System.exit(0); } });
4. 使用android.os.Process
//后台的进程被终结了 findViewById(R.id.button3).setOnClickListener(new OnClickListener(){ public void onClick(View v){ android.os.Process.killProcess(android.os.Process.myPid()); } });
目前为止,就懂得这么多,就这样先
相关文章推荐
- Android编码规范
- 《AndroidStudio每日一贴》4.如何快速插入引用?
- Android Studio Windows 10 Terminal 无法输入的解决方法
- Android中BaseAdapter的基本用法和加载自定义布局!
- Android开源项目分类
- Android Studio 新建Activity显示ActionBar
- android 应用的网络请求工具
- android 比较靠谱的图片压缩
- android使用junit进行单元测试
- [Android] 输入系统(一)
- Android自定义EditText样式
- android 动态创建控件并设置布局
- Android 利用addView 动态给Activity添加View组件
- android学习笔记
- Android原生Launcher的简要介绍及学习计划
- android:layout_weight 权重
- 第 2 章 Android 与 MVC 设计模式
- 介绍几个好用的android自定义控件
- android dp 和px的区别
- android:使用SurfaceView游戏开发简单屏幕适配方法