Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLEAR_TOP + start new activity. Hierarchy issue

Tags:

android

I have a hierarchy consisting of 4 levels of depth. My profile has the 2nd level of hieararchy that means that pressing back while being in the profile must always return user to the 1st hierarchy level.

My problem is that link to the profile is available on all levels; so, for instance, if a user being on the 4th level clicks on the profile link his hierarchy position must be changed to the 2nd level - NOT to the 5th.

I suppose there must be an essential way of doing it. So far I've come up with combination of CLEAR_TOP to the 1st level + if(extra){startActivity(Profile)} but in this way the 1st level activity will get recreated - right ? and that's why I want you to suggest something better.

Thanks guys :)

UPD: just to clarify a bit: there might not be an instance of Profile available, so simply clearing the top won't work in this case.

like image 785
midnight Avatar asked Jul 29 '12 19:07

midnight


1 Answers

In order to prevent 1st level MainActivity from recreating instead of plain CLEAR_TOP I added Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP. According to the documentation MainActivity gets onNewIntent invoked in case it has been already created.

Having done that I can switch on Intent data and launch any 2nd level activity

like image 126
midnight Avatar answered Nov 03 '22 23:11

midnight