Activity保存状态问题
我是 Android 应用程序开发的新手。我正在开发一个聊天(IM)应用程序。活动 A 显示联系人列表,活动 B 是聊天活动(对话活动)。从 A 活动中,当我单击联系人条目(来自联系人列表)时,我使用该联系人条目电子邮件地址启动活动 B(通过意图中的 putextra)。现在我想与另一个人聊天,我单击后退按钮并转到显示列表(联系人)的活动 A。我单击一个条目,然后使用不同的电子邮件地址再次启动活动 B(意图中的 putextra)。有时我会回来列出活动 A 并选择我正在聊天的上一个人。
现在我怎样才能停止创建新的活动并使用以前的状态从堆栈加载以前的活动??????
提前致谢。 原始编码器
I am new in android application development. I am working on a chat(IM) application. Activity A shows the contact list and activity B is the chat activity(conversation activity). From the A activity when i click on a contact entry(from the contactlist) i start activity B with that contact entry emailaddress(by putextra in the intent). Now i want to chat with another person and i click back button and go to the activity A showing the list(contact).I click one entry and again start activity B with different emailadd(putextra in the intent).After sometimes i get back to listactivity A and choose previous person i was chating.
Now how can i stop creating new activity and load the previous activity from the stack with the previous state??????
Thanks in advance.
Rawcoder
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您问如何拥有顶级活动的多个实例,那么您不能,只有一个顶级活动。
活动是在堆栈中创建的,当您从B创建A时,B现在位于堆栈的顶部,当您按下后退按钮时,您告诉android不再需要堆栈的顶层(当前活动)并且它被删除。
如果重新创建 B 时需要执行此操作,则您必须自己保存状态并恢复它。
类似问题
If you are asking how can have multiple instances of a top level activity, you cannot, there is only one top level activity.
Activities are created in a stack, when you create A from B then B is now at the top of the stack, when you press the back button you are telling android that the top level of the stack (current activity) is no longer needed and it gets removed.
You will have to save state yourself and restore it if that's what you need to do when B is recreated.
Similar Question