开发者

Android: How could a service start an Activity without old Activities in stack shown behind

Scenario:

Activity "A" launches Service "S".

Press 'Home'/'back' key to not to display "A".

Some time later "S" start intent Activity "B"

Intent intent = new Intent(context, MyDialog.class);
intent.setFlags(Intent.FLAG_ACTIVITY_N开发者_运维技巧EW_TASK);
startActivity(intent);

Current behaviour: "B" shows up with "A" behind in the scene.

What I want: "B" shows up without "A" benhind in the scene.

Note: Activity B is a Dialog Activity


First, you shouldn't do this. Services shouldn't start activities (in general). You don't want windows popping up on the user unless it's specifically asked for (ie texting app).

You could use the noHistory attribute on activity A if that suits your requirement. http://developer.android.com/guide/topics/manifest/activity-element.html#nohist

But as you're describing it, what you're seeing shouldn't happen, ESPECIALLY if you navigate away from A with the back button.


I believe you should be able to call finish(); as the last line below what you have here. Don't quote me on that though.


You can get answer from Android Service and AlertDialog Activity. Quoting the comment of Albin:

Add launchMode="singleInstance" in the manifest for the DialogActivity

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜