2

When "Logout" button clicked, app is clearing all data.

private void deleteAppData() {
    try {
        // clearing app data
        String packageName = context.getPackageName();
        Runtime runtime = Runtime.getRuntime();
        runtime.exec("pm clear " + packageName);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

How to set some listener for runtime.exec finish? When execution finished I would like to open Splash activity. Now app is closing only.

Question: how to start activity after runtime.exec completed?

Joe Rakhimov
  • 4,713
  • 9
  • 51
  • 109

2 Answers2

0

I think you should do this in OnDestroy or onStop() of the logout activity because the startActivity(i) will be called after runtime clears the data and then the application will transition into the other activity.

Sanoop Surendran
  • 3,484
  • 4
  • 28
  • 49
Wajdan Ali
  • 179
  • 13
0

Immediately after you start a new activity, using startActivity, make sure you call finish() so that the current activity is not stacked behind the new one.

 Intent mIntent = new Intent(mContext,MainActivity.class);
finishAffinity();
startActivity(mIntent);
Sunisha Guptan
  • 1,555
  • 17
  • 44
  • Question is about how to identify when runtime.exec finishes – Joe Rakhimov Jun 29 '17 at 12:02
  • Normally will clear the prefrence value after clearing the prefrence value it will redirect to the particular activiy the same way he can do.Also you have mentioned "When execution finished I would like to open Splash activity. Now app is closing only."For that am answering – Sunisha Guptan Jun 29 '17 at 12:04
  • In addition to preferences, I have SQLite database and Internal storage files . That's why I want to delete all data – Joe Rakhimov Jun 29 '17 at 12:05
  • Try to read this links https://stackoverflow.com/questions/31020705/how-can-check-runtime-execcmd-is-completed-or-not, https://stackoverflow.com/questions/6873830/in-java-determine-if-a-process-created-using-runtime-environment-has-finished-ex – Sunisha Guptan Jun 29 '17 at 12:06