如何将 Android App Widget Activity 堆栈与应用程序 Activity 堆栈分开?
我有一个 Android 应用程序小部件,单击它时会使用 PendingIntent
启动一个 Activity,与该应用程序小部件关联的主应用程序也使用该活动。当用户完成从 App Widget 启动的 Activity 并按下后退按钮后,用户将被带到主应用程序 Activity 堆栈顶部的 Activity。我想要后退按钮将用户带回 Android 桌面/主屏幕。
简而言之,我想要为我的应用程序小部件和应用程序使用单独的活动堆栈。不知道为什么 Android 想要将这些结合起来。
这就是我现在在应用程序小部件中得到的内容,但它不起作用。 Intent.FLAG_ACTIVITY_CLEAR_TOP
或 Intent.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有遇到过这种确切的情况,但
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.