I'm trying to implement a good Up navigation on my Android app.
For instance I want to go from DetailsActivity
to MasterActivity
. To do so I use the following code:
final Intent upIntent = new Intent(this, MasterActivity.class);
upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
supportNavigateUpTo(upIntent);
It works great if MasterActivity
is already open in the background: it closes the current activity (and all the activities in the stack over MasterActivity
) and fires the method onNewIntent
on MasterActivity
.
But, if MasterActivity
is not in the stack, the method simply closes DetailsActivity
and nothing else happens.
What I would like to achieve is that, if MasterActivity
is not in the stack, the current aActivity gets closed and a new instance of MasterActivity
gets created.
I already tried, with no success, the following flags combination:
Intent.FLAG_ACTIVITY_SINGLE_TOP
Intent.FLAG_ACTIVITY_CLEAR_TOP
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
Have you any idea on how to solve my issue?
Thanks a lot for your time
EDIT
The parent Activity need to be specified at runtime. In fact, the parent Activity can be ActivityA
,ActivityB
or ActivityC
.
Let me better explain the problem. My app manage TV Shows. I have a MainActivty
, a TVShowActivity
, a SeasonActivity
and a EpisodeActivity
.
In the navigation drawer from every Activity I want to be able to jump to the parent Activity:
-On EpisodeActivity
I want to go to SeasonActivity
, TVShowActivity
or MainActivity
;
-On SeasonActivity
I want to go TVShowActivity
or MainActivity
;
-On TVShowActivity
I want to go to MainActivity
.
My app currently works if my Activity stack is something like: MainActivty
=> TVShowActivity
=> SeasonActivity
=> EpisodeActivity
.
The problem is that sometimes the user can reach EpisodeActivity
directly from MainActivity
, and I want to be able to use the same navigation pattern.