android:在不弹出活动的情况下移动它们
我希望实现以下目标:
活动 A ->活动B
活动B ->活动 A
从纸面上看,这听起来与按下后退按钮是一样的。问题是,我不希望 Activity B 被弹出。
我需要类似于 moveTaskToBackground 的东西,但对于单个活动。这样当我再次从 A 返回时,它就可以恢复。
为了给您一些背景信息,活动 A 是一个项目列表。活动 B 显示有关该项目的信息并播放附加到该项目的歌曲。从 B 返回到 A 时,我希望继续播放该歌曲,这样如果该人在 A 中点击相同的选项,他们就会恢复活动。否则终止该活动并开始具有新细节的新活动并播放新歌曲。
I have the following I wish to achieve:
Activity A -> Activity B
Activity B -> Activity A
On paper it sounds like the same thing as just hitting the back button. Problem is, I don't want Activity B to be popped.
I need something along the lines of moveTaskToBackground but for a single activity. That way when I go back to it from A again, it can resume.
To give you some context, Activity A is a list of items. Activity B displays information about the item and plays a song attached to it. While going back from B to A, I want that song to keep playing, that way if the person hits the same option in A they just resume the activity. Otherwise kill that activity and start a new one with the new details and play the new song.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要查看 ActivityGroup 和 LocalActivityManager。 TabActivity(如其他答案中所建议的)实际上扩展了 ActivityGroup。
下面是一个帮助您入门的简单示例:
使用它来启动活动 A:
或使用它来启动活动 B:
活动被缓存并与指定的 ID 关联。如果您使用相同的 id 多次调用 startActivity,则实际使用缓存的活动(并非总是如此,取决于您使用的意图)。如果需要,您可以轻松地从缓存中删除任何活动。查看 LocalActivityManager 了解更多详细信息。
You need to look into ActivityGroup and LocalActivityManager. TabActivity (as suggested in other answer) actually extends ActivityGroup.
Here is a quick example to get you started:
Use this to start activity A:
or this to start activity B:
Activities are cached and associated with specified IDs. If you invoke startActivity with the same id several times, then cached activity is actually used (not always, depends on intents you use). You can easily remove any activity from cache if you need. Look into LocalActivityManager for more details.
您可以使用 TabActivity 在 Activity 之间切换。您可以在代码中进行切换。只需隐藏用户界面中的选项卡即可。
以下是有关如何开始的快速教程: http://developer.android .com/resources/tutorials/views/hello-tabwidget.html
You can use a TabActivity to switch between activities. You can do the switching within the code. Just hide the tabs in your UI.
Here's a quick tutorial on how to get started: http://developer.android.com/resources/tutorials/views/hello-tabwidget.html