Search code examples
androidsingle-instance

How to close all of the activities of running app and Re-launch a fresh app on click


I'm having the app with multiple screen My App Launch from splash(Launcher)->Home Screen->Child Screen. When User Tap on URL app directly jumps to Child Screen(Application need). But when user tap on URL a new instance of application launched which I don't want. I want to close the the existing app and launch the fresh app with Child Screen. Each activity is having android:launchMode="singleTop"


Solution

  • To launch the fresh Application I found this solution and its working fine for me

    Intent intent = new Intent(Firstctivity.this, SecondActivity.class);
    intent .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent );
    finish();
    

    It will close ongoing Task and create new one for me.. :)