Android 重启app的一些方法
来源:互联网 发布:正版ai软件多少钱 编辑:程序博客网 时间:2024/06/16 03:34
有的时候需要重新启动app,有两种可行的方案:
a. 使用 FLAG_ACTIVITY_CLEAR_TOP :
Intent i = getBaseContext().getPackageManager() .getLaunchIntentForPackage(getBaseContext().getPackageName()); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i);
b. 使用 AlarmManager :
Intent intent = getBaseContext().getPackageManager() .getLaunchIntentForPackage(getBaseContext().getPackageName()); PendingIntent restartIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT); AlarmManager mgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, restartIntent); // 1秒钟后重启应用 System.exit(0);
经过测试发现两种都可以实现,但是当默认启动的activity的launchMode 设置为不是以”standard” 方式启动时,这个时候重启app不能清除activity中的内存数据。
不知道还有没有其他的方法。。
2 0
- Android 重启app的一些方法
- Android使用service重启APP的方法
- android重启APP
- ### Android 判断app的状态 重启app
- android开发 重启app
- android关闭重启app
- android--Service自动重启而不被kill掉的一些方法
- android--Service自动重启而不被kill掉的一些方法
- Android中操作App的一些常用方法
- android 重启手机的方法
- Android实现关机重启的方法
- Android 应用 重启的方法
- android重启应用的方法
- Android 重启APP application 代码 code restart android app
- iOS代码重构的一些方法
- Android app实现重启、关机功能
- Android重启app功能实现
- android重启自身应用APP
- VectorDrawable-第三章
- 机器学习 Python实现逻辑回归
- 二分查找的Java实现
- Python中的闭包问题
- Eclipse的远程调试(附)
- Android 重启app的一些方法
- 敏捷开发之Scrum扫盲篇
- linux下通过编写测试程序的方式来确认arm-linux-gnueabihf-gcc-4.6lib和.h文件的安装位置,为复制libnl做准备
- JQuery处理json与ajax返回JSON实例
- Python_cmd的各种实现方法及优劣(subprocess.Popen, os.system和commands.getstatusoutput)
- 在Linux中划分partition 并格式化为文件系统
- iOS音频播放 (四):AudioFile
- 详解IP地址后面斜杠加具体数字
- 敏捷开发Scrum 学习笔记,适于移动开发