Notification Resume Activity

别等时光非礼了梦想. 提交于 2019-11-30 13:04:17

What is happening here is a little confusing so bear with me here.

FLAG_ACTIVITY_SINGLE_TOP according to the docs If set, the activity will not be launched if it is already running at the top of the history stack. So if the current activity is not at the top of the history stack it will be relaunched.

FLAG_ACTIVITY_CLEAR_TOP again from the docs If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

By default the TabActivity will always open to tab 0, you can use setDefaultTab to change that via code. Each Tab in the TabHost is also a new Intent

If I compile it like this, and click on the Notification, it opens a NEW tabactivity on the first tab. If I click back then, I get alot of errors (database is still open, nullpointers and stuff).

This is happening I think because the current Intent is tab4 (in reality its #3, 0,1,2,3) and your notification is bringing up the tabactivity.class. Since it is not active or on top of the stack, every act on top of it is closed, including tab4.

So, what I want is, that I can do the following: I open my app, go to the tabactivity, open tab 4, click record. If I click back then, it should hide the app, also, if I just click the home button. But there is a notification. If I click on that one, it should just show the hidden acitivity again and thats it. So, what I am doing wrong there? I thought, the Flags FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP should solve the problem?

You are confusing what the flags do and what happens with the home and back keys. Hitting home will hide your activity and the notification should work fine with those flags (once you fix the problem I mentioned earlier). When you hit back though, Android ends the current Activity and takes it off the stack. Since there is nothing under it, you are forced to relaunch from scratch when you press the notification.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!