如何将 Android App Widget Activity 堆栈与应用程序 Activity 堆栈分开?

发布于 2024-09-30 12:50:15 字数 731 浏览 1 评论 0原文

我有一个 Android 应用程序小部件,单击它时会使用 PendingIntent 启动一个 Activity,与该应用程序小部件关联的主应用程序也使用该活动。当用户完成从 App Widget 启动的 Activity 并按下后退按钮后,用户将被带到主应用程序 Activity 堆栈顶部的 Activity。我想要后退按钮将用户带回 Android 桌面/主屏幕。

简而言之,我想要为我的应用程序小部件和应用程序使用单独的活动堆栈。不知道为什么 Android 想要将这些结合起来。

这就是我现在在应用程序小部件中得到的内容,但它不起作用。 Intent.FLAG_ACTIVITY_CLEAR_TOPIntent.FLAG_ACTIVITY_NEW_TASK 似乎都对堆栈没有任何影响。

Intent intent = buildWidgetIntent(context, info);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

PendingIntent pendingIntent = PendingIntent.getActivity(context,
mRequestCode++, intent, PendingIntent.FLAG_UPDATE_CURRENT);

感谢您对此的任何帮助。

I've got an Android App Widget that when clicked uses a PendingIntent to start an Activity, which the main Application associated with the App Widget also uses. After the user is done with the Activity started from the App Widget, and presses the back button, the user is taken to the Activity on the top of the MAIN application Activity stack. I'd like the back button to take the user back to the Android desktop/home screen.

In short, I'd like separate Activity stacks for my App Widget and Application. Not sure why Android wants to combine these.

This is what I've got now in the App Widget and it's not working. Neither Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK seems to have any impact on the stack.

Intent intent = buildWidgetIntent(context, info);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

PendingIntent pendingIntent = PendingIntent.getActivity(context,
mRequestCode++, intent, PendingIntent.FLAG_UPDATE_CURRENT);

Thanks for any help with this one.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

蹲在坟头点根烟 2024-10-07 12:50:15

我还没有遇到过这种确切的情况,但 Intent.FLAG_ACTIVITY_NO_HISTORY 是我需要使我的小部件启动的 Activity 始终返回主屏幕。

I haven't faced this exact situation, but Intent.FLAG_ACTIVITY_NO_HISTORY is what I needed to make my widget-launched Activity always go Back to the Home screen.

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