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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With