There can be many activities in application and the last launched activity stay on top of stack and on pressing back it finish the current activity.I have a sequence of Activity and here is the flow ..
if we have A,B,C(1),D,C(2)... Activity C(1) and C(2) are two different instance of Activity C launched while navigating the application .So what is requisite is to clear all the instance of activity C and the result should be when I finish C(2) I should have left with these stack A,B,D. What should I do .
IMP -I want to keep the C(1) alive in stack until unless I finish the C(2) as I could have started C with New Task flag rather than creating these instances , but these instance have different UI and work .
The following approaches are not favorable .
First
@Override
public void onBackPressed(){
super.onBackPressed();
Intent intent = new Intent(C(2).this , D.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
startActivity(intent);
}
This will clear All the activity from Stack and relaunch Activity
Second
Keep the track of Activity in singleton class and then relaunching the required flow, how ever this will consume the time when there are many Activities to be started .
So I thought that there should be some solution using package manager or other that will resolve the problem , solution are appreciated