Search code examples
androidbackground-process

Restart android app after cache clear


I am using clearApplicationUserData() for clear the app cache after install an update of the android application. Once above method runs, app close immediately. Any suggestion to restart the app after close the app itself?

if (Build.VERSION_CODES.KITKAT <= Build.VERSION.SDK_INT) {
    ((ActivityManager)SplashScreenActivity.this.getSystemService(ACTIVITY_SERVICE))
            .clearApplicationUserData(); 
    Toast.makeText(getApplicationContext(), "Cache cleared", Toast.LENGTH_LONG).show();
}

Solution

    1. you can create a local broadcast receiver and a BroadcastReceiver that would listen to it.
    2. Inside onDestroy or onStop call your MainActivity.