Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
767 views
in Technique[技术] by (71.8m points)

broadcastreceiver - Android launch an activity from a broadcast receiver

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...