我怎么可以保存应用程序恢复堆栈捆绑? [英] How can I save the application back stack to a bundle?

查看:213
本文介绍了我怎么可以保存应用程序恢复堆栈捆绑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想救我的应用程序的状态,这样,当它从关闭状态重新打开,最后一个片段是可见的,后面的堆栈preserved。我想每次preserve这种状态下,应用程序是封闭的,不只是在一个方向改变或系统杀死应用程序,以腾出资源(如在使用的情况下的onSaveInstanceState( ) / onRestoreInstanceState()

I'd like to save the state of my application so that when it is reopened from a closed state, the last fragment is visible and the back stack is preserved. I'd like to preserve this state every time the application is closed, not just on an orientation change or when the system kills the app to free up resources (as is the case when using onSaveInstanceState()/onRestoreInstanceState().

到目前为止,我已经能够恢复previous碎片,它的状态,计划通过保存状态共享preferences后来又恢复了。但是,这并不preserve片段回栈,因此当用户加载的应用程序和presses后退按钮的应用程序流动起来,应用程序退出,而不是往上走。

So far I've been able to restore the previous fragment and its state as planned by saving the state to SharedPreferences and restoring it later. However, this does not preserve the fragment back stack, so when the user loads the application and presses the back button to move "up" in the application flow, the app quits instead of going up.

我需要在这一点上是能够获得访问应用程序恢复堆栈并将其保存到一个捆绑在必要的时候,远在的onSaveInstanceState系统做(的方式)。我读过的 FragmentManager.saveFragmentInstanceState()的说明文件,但我不知道如何使用它来实现我的目标。任何人都可以点我在正确的方向?

What I need at this point is to be able to get access to the application back stack and save it to a bundle when necessary, much the way the system does in onSaveInstanceState(). I've read the documentation for FragmentManager.saveFragmentInstanceState() but I'm not sure how to use this to accomplish my goal. Can anybody point me in the right direction?

我使用的片段实现从Android兼容性库。

I'm using the fragment implementation from the Android compatibility library.

推荐答案

据我所知,Android系统不会让你获得任务的背部栈,它只能<一href="http://developer.android.com/reference/android/app/ActivityManager.html#getRunningTasks%28int%29"相对=nofollow>给你中运行的所有任务顶部活动。因此,你需要实现自己保持活动返回堆栈的机制。实施<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.2_r1.1/android/app/LocalActivityManager.java/"相对=nofollow> LocalActivityManager 可以帮助你,尤其是,它的<一个href="http://developer.android.com/reference/android/app/LocalActivityManager.html#saveInstanceState%28%29"相对=nofollow> saveInstanceState() 方法。所以,你可能会做同样的事情,并呼吁的onSaveInstanceState(捆绑)活动在你的背部栈,只要你想,然后持续捆绑(在一个文件中,例如)。如果你使用片段,那么你还需要保持其回堆栈。

As far as I know Android system won't let you get the task's back stack, it can only give you the top Activity of all tasks running. Hence, you will need to implement your own mechanism of maintaining the Activities back stack. Implementation of LocalActivityManager might help you, particularly, its saveInstanceState() method. So you may do something similar and call onSaveInstanceState(Bundle) of Activities in your back stack whenever you want and then persist Bundle (in a file, for example). If you use Fragments then you will also need to maintain their back stack.

也许, 安卓alwaysRetainTaskState 可以帮助你解决你的问题没有深入到后面的管理堆栈。

Perhaps, android:alwaysRetainTaskState might help you to solve your problem not diving into managing back stack.

这篇关于我怎么可以保存应用程序恢复堆栈捆绑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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