开发者

Starting a different task from Android

My app can be opened from two different contexts:

(1) From the home screen (2) From a notification in the title bar.

If the app is opened from the notification, it starts Activity B, and hen the user is done with this activity, I would like to close out of the app. I don't want it to return to another activity in the activity stack if the app has been opened previously from context (1) above.

For example, if I open the app from the home screen, then press home, and then open the app from a notification in the title bar, when I am done with Activity B it takes me back to the main activity for my app. I don't want it to do this.

I would really like to be able to start the activity stack afresh when I open the activity from a notification.

I have tried adding the flags

FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_CLEAR_TOP

But this doesn't seem to help. Alternatively, I also tried setting noHistory="true" inside the activities in my app, but this really doesn't work well if the user opens the app from context (1).

Any ideas? Is there any way to start the activity stack fresh when you open the 开发者_高级运维app from a different context?


You could call finish() from the onStop() method of ActivityA that way when the user is inside of this activity and presses the home button the activity will finish and no longer be on the stack. Then when they open ActivityB from the notification bar and get done with it they will be taken back to the homescreen (or another activity if they were inside of something when they opened you from the notification bar).


In the AndroidManifest, you should add android:clearTaskOnLaunch="true" for Activity B. It means that it will start a new task for activity B each time it is launched.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜