本文介绍了如何重用活动?不是每次创建活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这话题是继续这样的:

This topic is continue of this:Android. How to start activity without creating new one?

我已阅读,活动被破坏时,单击后退按钮。
它们可以不被破坏时,将更深地堆栈,然后调用活动回来。使用的android:launchMode =singleTask例如:

I have read that activities are destroyed when to click BACK button.They can be not destroyed when to move deeper to stack and then call activities back. using android:launchMode="singleTask" for example

是有可能,当我点击后退按钮,然后再次运行活动活动不被破坏?

is it possible that activities to not be destroyed when I click button BACK and then run activity again?

推荐答案

返回按钮的默认实现为终点当前活动。您可以但是拦截键preSS和做任何你想用它。例如,而不是完成你的当前活动,你可以弹出的previous活性,从而使它看起来好像正常实现就在眼前。

The default implementation of the back button is the finish the current activity. You may however intercept that key press and do whatever you wish with it. For instance, instead of finishing your current activity, you could "bring up" the previous activity and thus making it seem as if the normal implementation is at hand.

要拦截后退按钮preSS:

To intercept the back button press: Android: intercepting back key

和没有创建一个新的每次启动previous活动:

And to start your previous activity without creating a new one every time:

Intent i = new Intent(getApplicationContext(), PreviousActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);

祝你好运。

这篇关于如何重用活动?不是每次创建活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:54