How do I open the same current activity as a new one?
I have an Activity that was used to start another according to the button that was pressed, the new one will be either completely new or as at the current moment. So, when starting a new one, I get the animation being created like this:
but when starting the same activity, I got one of two ways:
1 - when starting vie, the recreate()
activity just blinks to change stats (which is pretty normal)
2 - when working with it as if it was a different action, using intent()
with a flag CLEAR_TOP
, I got this:
-
I've already used:
Intent intent; // 1 (dealing with it as a whole new one by passing the Activity Class) intent = new Intent(v.getContext(), MyActivity.class); intent.putExtra("EXIT", false); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); finish(); // 2 (just getting the current one directly) intent = getIntent(); finish(); startActivity(intent);
- for two ways:
So how to open the same open activity with the animation of opening a new one? (i.e. as in the first picture)
source to share
found a solution using CLEAR_TASK
intent flag which according to that link will cause any existing task that would be associated with the activity to be cleared before the activity is started.
So it will be like this:
Intent intent = new Intent(v.getContext(),
MyActivity.class);
intent.putExtra("EXIT", false);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // Here We Are
startActivity(intent);
finish();
source to share