Android 从广播接收器启动 Activity

发布于 2024-10-10 22:06:44 字数 790 浏览 6 评论 0原文

我知道这可能不是最佳实践,但这就是我想做的。

当我的广播接收器被调用时 - 启动一个新活动,该活动不是全屏且具有透明背景 - 它在当前活动/桌面壁纸之上打开。

到目前为止,我的代码如下:

我创建并调用一个新活动:


  Intent testActivityIntent = new Intent(context, com.andy.tabletsms.work.SMSPopup.class);
                testActivityIntent.putExtra("com.andy.tabletsms.message", main.msgs.get(i));
                testActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                testActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                context.startActivity(testActivityIntent);

然后该活动的主题为:

android:theme="@android:style/Theme.Translucent.NoTitleBar"

以及该活动的代码只是一个布局简单的沼泽标准活动。然而,当该广播接收器启动该活动时 - 它出现在应用程序启动时启动的上一个活动的顶部......如下图所示: 替代文本

I know it may not be best practice but this is what i want to do.

When my broadcast receiver is called - start a new activity which has is not fullscreen and has a transparent background - which opens on top of your current activity / desktop wallpaper.

The code I have so far is as follows:

I create + call a new activity with :


  Intent testActivityIntent = new Intent(context, com.andy.tabletsms.work.SMSPopup.class);
                testActivityIntent.putExtra("com.andy.tabletsms.message", main.msgs.get(i));
                testActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                testActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                context.startActivity(testActivityIntent);

And then the activity has a theme of :

android:theme="@android:style/Theme.Translucent.NoTitleBar"

And the code of the activity is just a bog standard activity with a simple layout. However when that broadcast receiver starts the activity - it appears on top of the previous activity which was started when the applicaiton started.....as per this image shows :
alt text

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

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

发布评论

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

评论(3

坦然微笑 2024-10-17 22:06:44

这与我在上一个问题中回答的问题相关:活动从活动堆栈顶部打开的通知开始

基本上都是关于:android:taskAffinityandroid:launchMode

This is related to the problem I answered in a previous question here: Activity started from notification opened on top of the activity stack

Basically it's all about: android:taskAffinity and android:launchMode

怀中猫帐中妖 2024-10-17 22:06:44

您已经问了大约 3 次同样的问题,但我们仍然没有足够的信息。您一直提到“原始活动”,但我们不知道那是什么,您如何开始它,或者它去哪里以至于它“回来”。

您可能没有完成“主要”活动,或者您有奇怪的标志,或者它正在监听相同的意图。

您也不向我们展示有关您的广播接收器的任何信息。

You've asked this same question like 3 times now and we still don't have nearly enough information. You keep mentioning the "original activity" but we have no idea what that is, how you started it, or where it went such that it "comes back".

Your probably is you're probably not finishing your "main" activity, or that you have weird flags, or it's listening for the same intent.

You also don't show us anything about your broadcast receiver.

留蓝 2024-10-17 22:06:44

不要使用
android:theme="@android:style/Theme.Translucent.NoTitleBar"
将 android:theme 保留为默认值。这对我有用

Dont use
android:theme="@android:style/Theme.Translucent.NoTitleBar"
leave the android:theme as the default.This works for me

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