How do I programmatically "clear the app data " and then “restart” an Android app? Already tried with below links:
Restart android app after cache clear
How do I programmatically "clear the app data " and then “restart” an Android app? Already tried with below links:
Restart android app after cache clear
After calling .clearApplicationUserData()
application is killed.
So you can have only one of those - clear app data, or restart app.
If you want just to clear DB or some files stored by app that you know of, you can do it manually, and then restart app, but if you want to completely erase all user data you need to shut app, and maybe before that inform user that he will need to manually start app again.
I don't know about "clearing app data" but you can restart the app by using this method.
private void restartApp() {
Intent intent = new Intent(getApplicationContext(), YourActivityHere.class);
int mPendingIntentId = 2;
PendingIntent mPendingIntent = PendingIntent.getActivity(getApplicationContext(), mPendingIntentId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
System.exit(0);
}