Android的 - 重振的活动,而无需重新创建 [英] Android - Relaunching an activity without having to re-create it

查看:117
本文介绍了Android的 - 重振的活动,而无需重新创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动,显示的图像(ViewCollection.java)。我想一次只创建它,然后重新使用该实例进一步表明,从不同的调用更多图像(该活动是昂贵的初始化)。 到目前为止,我公司推出的活动是这样的:

I have an activity which shows an image (ViewCollection.java). I want to only create it once, then re-use that instance to further show more images from different calls (The activity is expensive to initialize). So far, I launched the activity like this:

Intent i = new Intent(this, ViewCollection.java);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

和从ViewCollection活动的所有活动电话也被称为用同样的方法。 虽然如此,该活动不断得到当我开始其他活动,从中摧毁... 我能做些什么来解决这个问题?

And all activity calls from the ViewCollection activity are also called by the same method. But despite this, the activity keeps getting destroyed when I start other activities from it... What can I do to fix this?

* PS:活动被设置为标准的发射模式

*PS: The activity is set to "standard" launch mode

推荐答案

设置活动launchmode到singletop或设置标志 FLAG_ACTIVITY_SINGLE_TOP
处理中onNewIntent的意图() 您可以进一步得到<一href="http://developer.android.com/reference/android/app/Activity.html#onNewIntent%28android.content.Intent%29"相对=nofollow>此处细节

Set the activity launchmode to singletop or set the flag FLAG_ACTIVITY_SINGLE_TOP .
Handle the intent in onNewIntent() You can get further details here

编辑:虽然因为你进入应用程序最后一次,如果返回键是pssed上的活动或配置$ P $改变,活动还是会重新

Though if back key is pressed on the activity or configuration changed since last time you entered the app, the activity will still be recreated

这篇关于Android的 - 重振的活动,而无需重新创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆