Android 从广播接收器启动 Activity
我知道这可能不是最佳实践,但这就是我想做的。
当我的广播接收器被调用时 - 启动一个新活动,该活动不是全屏且具有透明背景 - 它在当前活动/桌面壁纸之上打开。
到目前为止,我的代码如下:
我创建并调用一个新活动:
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 :
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这与我在上一个问题中回答的问题相关:活动从活动堆栈顶部打开的通知开始
基本上都是关于:
android:taskAffinity
和android: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
andandroid:launchMode
您已经问了大约 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.
不要使用
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