Android的 - 重振的活动,而无需重新创建Android

由网友(荒年i)分享简介:我有一个活动,显示的图像(ViewCollection.java)。我想一次只创建它,然后重新使用该实例进一步表明,从不同的调用更多图像(该活动是昂贵的初始化)。到目前为止,我公司推出的活动是这样的:I have an activity which shows an image (ViewCollection.ja...

我有一个活动,显示的图像(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的意图() 您可以进一步得到此处细节

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

阅读全文

相关推荐

最新文章