Search code examples
androidandroid-activityandroid-widgetback-stack

How to close all activity before launch new activity from AppWidgetProvider android


Hi I want to close all activity before launch new activity from AppWidgetProvider. I'm not having idea to do this. could you please suggest me any idea to do this?


Solution

  • you can use finishAffinity() method (from Activity, doc here). launch dummy invisible/transparent Activity, finishAffinity all Activityies and startActivity with proper Intent

    there are also some flags for Intents which should clear your Activity backstack, but it depends on declared launchMode in Manifest. you may check these

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    

    or

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);