android:在不弹出活动的情况下移动它们

发布于 2024-10-11 00:41:04 字数 324 浏览 3 评论 0原文

我希望实现以下目标:

活动 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

书信已泛黄 2024-10-18 00:41:04

您需要查看 ActivityGroupLocalActivityManager。 TabActivity(如其他答案中所建议的)实际上扩展了 ActivityGroup。

下面是一个帮助您入门的简单示例:

使用它来启动活动 A:

LocalActivityManager manager =  getLocalActivityManager();  

//A_ID == 1
Window activityWindow = manager.startActivity(A_ID, intent_activityA); 
setContentView(activityWindow.getDecorView());

或使用它来启动活动 B:

//B_ID == 2
Window activityWindow = manager.startActivity(B_ID, intent_activityB);
setContentView(activityWindow.getDecorView());

活动被缓存并与指定的 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:

LocalActivityManager manager =  getLocalActivityManager();  

//A_ID == 1
Window activityWindow = manager.startActivity(A_ID, intent_activityA); 
setContentView(activityWindow.getDecorView());

or this to start activity B:

//B_ID == 2
Window activityWindow = manager.startActivity(B_ID, intent_activityB);
setContentView(activityWindow.getDecorView());

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.

神经大条 2024-10-18 00:41:04

您可以使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文