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

编程入门 行业动态 更新时间:2024-10-11 23:23:09
本文介绍了重新启动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应用程序被杀害后,

本文发布于:2023-11-27 13:21:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638247.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重新启动   被杀   应用程序   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!