安卓:返回previous活动,而无需调用完成() [英] Android: Return to previous activity without calling finish()

查看:127
本文介绍了安卓:返回previous活动,而无需调用完成()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序的活动很多,想的东西像一本书,每一个页面是一项新的活动。用户可以改变每个活动,例如突出某些文本用不同颜色的标记等,它是至关重要的,我只要记住这个信息作为应用程序保持活着(我不想/需要记住任何这个时候它不是)。据我所知,用于存储这类信息的最佳机制是通过的onSaveInstanceState(包outState)的onCreate(捆绑) / onRestoreInstanceState(捆绑),而不是可以说,在preferences机制。我唯一​​的问题是,用户可以向后导航到previous页面(活动),我所知道的实现,这是唯一的方法调用完成()这当然杀死当前的活动,而不调用的onSaveInstanceState(包outState)键,即使它调用它,下次我将推出一项活动再presenting该网页将是一个全新的实例。所以我的问题是:有没有办法回去了previous活动,而无需调用完成()?或者,是否有更好的方法来保存这些信息?也许通过静态变量?

I have an android application with a LOT of activities, think of something like a book where every page is a new activity. The user can make changes in each activity, for example highlight certain texts with different colored markers etc. and it's crucial that I'll remember this information as long as the application stays alive (and I don't want/need to remember any of this when it's not). As I understand the best mechanism for storing this kind of information is via onSaveInstanceState(Bundle outState) and onCreate(Bundle)/onRestoreInstanceState(Bundle) rather than lets say, the Preferences mechanism. My only problem is that the user can navigate backwards to previous pages (Activities) and the only way i know of achieving this is by calling finish() which of course kills the current activity without calling onSaveInstanceState(Bundle outState) and even if it did call it, the next time I would launch an activity representing that page it would be an entirely new instance. So my question is: Is there a way to go back to the previous activity without calling finish()? or, is there a better way to save this information? maybe through static variables?

谢谢!

P.S。 我知道我还可以实现我的应用程序不同,因此,不是每个页面将有自己的活动,但是这不是我要找的答案。

P.S. I know I could also implement my app differently so that not every page would have its own activity but this isn't the answer I'm looking for.

推荐答案

尝试使用startActivity()与标志,如Intent.FLAG_ACTIVITY_CLEAR_TOP。 你可以在这里阅读完整的故事: <一href="http://developer.android.com/reference/android/content/Intent.html#setFlags(int">http://developer.android.com/reference/android/content/Intent.html#setFlags(int)

Try to use startActivity() with flags such as Intent.FLAG_ACTIVITY_CLEAR_TOP. You could read the full story here: http://developer.android.com/reference/android/content/Intent.html#setFlags(int)

这篇关于安卓:返回previous活动,而无需调用完成()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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