开发者

Problem on launching Activity from other application

开发者 https://www.devze.com 2023-02-24 04:18 出处:网络
I have met a problem, hope you can provide some suggestion on it. Here is the problem: There is an A Activity in my application which is the application\'s MAIN Activity, and can be started from oth

I have met a problem, hope you can provide some suggestion on it.

Here is the problem:

There is an A Activity in my application which is the application's MAIN Activity, and can be started from other application(like SMS). Consider now there are A-B-C-D activities in my application's task, as I said before, user can start A Activity from SMS, when A is launched from SMS, I want B C D all to be finished, and the in开发者_如何学Pythonstance of A Activity in the task will be brought to front.

I tried to set A activity's launchMode to singleTask, this will do the trick, but there is another problem: for example, I got A-B-C-D Activities in my application's task, user press HOME key to the home screen, and re-launch the application from the launcher, then A Activity is shown instead of D Activity. It's like the application have been started from the beginning, that is not what I want.

Is there any way that I can do this? Any suggestion will be highly appreciated. Thanks in advance!


Haven't tried it, but you can try this:

  1. Set the activity attribute alwaysRetainTaskState to true. This should take care to retain all the activities in the stack.
  2. When you want the root activity to be shown (In your case : when launched from SMS - I assume you are invoking the activity from your SMS receiver using start activity), in the intent you pass to startActivity set the FLAG_ACTIVITY_CLEAR_TOP flag. This should clear off since you explicitly mention it in the Intent.
0

精彩评论

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

关注公众号