Android中重启应用的几种方法

Android中重启应用的几种方法方法一:Intentintent=newIntent(LoginActivity.this,LoginActivity.class);startActivity(intent);System.exit(0);finish();说明:其中,LoginActivity为重启后的界面,点击重启功能之后,应用是不会走onDestroy()方法,直接走onCreate()–>onResume()。方法二:Intentintent=getBaseContext().getPa

Android中重启应用的几种方法"

方法一:

Intent intent = new Intent(LoginActivity.this, LoginActivity.class);
startActivity(intent);
System.exit(0);
finish();

说明: 其中,LoginActivity为重启后的界面,点击重启功能之后,应用是不会走onDestroy()方法,直接走onCreate()–>onResume()。

方法二:

Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
//与正常页面跳转一样可传递序列化数据,在Launch页面内获得
intent.putExtra("REBOOT","reboot");
PendingIntent restartIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager mgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, restartIntent);
android.os.Process.killProcess(android.os.Process.myPid());

说明:点击重启功能之后,应用是不会走onDestroy()方法,直接走onCreate()–>onResume()。

方法三:

Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//与正常页面跳转一样可传递序列化数据, 在Launch页面内获得
intent.putExtra("REBOOT","reboot");
startActivity(intent);

说明:点击重启功能之后,应用是会走启动初始界面onCreate()–>onResume(),之后走最后activity的onDestory()方法。

今天的文章Android中重启应用的几种方法分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:http://bianchenghao.cn/30993.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注