本文介绍了重新启动Android应用程序被杀害后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序处于空闲状态,Android的终止进程。如果用户重新打开了一段时间后的应用程序时,只有在创建顶活动 - 这是我的一个问题,因为该活性取决于其它的目的(其现在破坏)

When my application is idle, Android kills the process.If user reopens the application after some time, only the top Activity is created - this is a problem for me because the activity depends on initialization of other objects (which are now destroyed).

我想在这种情况下是要重新启动应用程序。我该怎么办呢?

What I want to do in that case is to re-launch the application.How can I do that?

推荐答案

只需确定你的应用程序正在启动后,这是previously搭载Android摧毁,你能做到这一点通过保持一个变量在自定义的应用程序类,并将其设置为后,您的应用程序了初始化。因此,当applicaction重新启动,这个标志是假的,然后只是让一个意图来启动主活动指定 FLAG_ACTIVITY_CLEAR_TOP

Just identify that your Application is being launched after it was previously destroyed by Android, you could do this by keeping a variable in a custom Application class, and set it to true after your applicaiton is initialized. So when the applicaction is re-launched, this flag is false, and then just make an Intent to launch your main Activity specifying FLAG_ACTIVITY_CLEAR_TOP :

Intent reLaunchMain=new Intent(this,MainActivity.class);
reLaunchMain.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(reLaunchMain);

这篇关于重新启动Android应用程序被杀害后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 00:56
查看更多