重新启动Android应用程序被杀害后,重新启动、被杀、应用程序、Android

由网友(真心碎了一地)分享简介:在我的应用程序处于空闲状态,Android的终止进程。如果用户重新打开了一段时间后的应用程序时,只有在创建顶活动 - 这是我的一个问题,因为该活性取决于其它的目的(其现在破坏)When my application is idle, Android kills the process.If user reopen...

在我的应用程序处于空闲状态,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);
阅读全文

相关推荐

最新文章