Android活动堆栈 [英] Android activity stack

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

问题描述





我的情况是我将完成5项活动。 A,B,C,d,E。在活动堆栈中,只有三个活动,即A,B,E或A,C,E或A,D,E,因此活动A和E应该在堆栈中,其他活动状态也应保存,以便我可以获得之前的活动。



完成此任务我有以下疑问



1.How检查某个特定活动是否已经在堆栈中。



2.如果它是如何保存其状态以便我可以用新活动替换当前活动。



3.如何用另一项活动替换一项活动,但保持旧活动的状态。





如果你给我正确的解决方案我会很感激你

Hi ,

I have a situation where i will have totally 5 activities. A,B,C,D,E. In activity stack there can be only three activities that is A,B,E or A,C,E or A,D,E so Activity A and E should be there in stack also other activities state should be saved so that i can get the activity as it was before.

to complete this task i have following queries

1.How to check whether a particular activity is there in stack already.

2. if it is there how to save its state so that i can replace the current activity with new activity.

3.How to replace one activity with another activity but keeping the state of the old activity.


I would be thankful to you if u give me the correct solutions

推荐答案

我不知道你为什么要维护自己堆栈,因为android已经保留了一堆活动:启动一个活动将一个活动推到堆栈上,然后从堆栈弹出它。



我支持决定参与活动A你的下一个活动b,C或D应该做什么。但是从你的描述我不知道你的用例是否允许这个决定。



关于保存你的活动状态:看看重新开展活动
I'm not sure why you want to maintain the stack yourself, as android already keeps a stack of the activities: starting an activity pushes one on the stack, going back pops it from the stack.

I suppose deciding in activity A what will be your next activity b, C or D should do it. But then from your description I cannot tell if your use case allows for this decision.

about saving your activities state: check out Recreating an Activity


1。使用ActivityManager查找正在运行的活动 http://developer.android.com/reference/android/app/ActivityManager。 html [ ^ ]

2.活动暂停时应保存活动状态。以新状态开始新活动。

3.不要替换。只需创建一个新的。或者您可以恢复之前的活动并通过setResult发回更改的数据。前提条件是你应该使用startActivityForResult而不仅仅是startActivity
1. use ActivityManager to find running activities http://developer.android.com/reference/android/app/ActivityManager.html[^]
2. the activity states should be saved when the activity is paused. start a new activity with new state.
3. don't replace. just create a new one. or you can resume the previous activity and send changed data back by setResult. The pre-condition is you should use startActivityForResult not just startActivity


这篇关于Android活动堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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