0

My app has a restore feature which allows to replace the current database and settings with a the one from a backup file.

The app reacts to the backup opening through intent-filters I have some code to handle the file in an Activity onCreate method

if (Intent.ACTION_VIEW.equals(intent.getAction())) {
String scheme = intent.getScheme();
// valid scheme are files or content in case of mail attachment
    if (scheme.equals("file") || scheme.equals("content")) {
        uri = getIntent().getData();
    } else if (scheme.equals("http") || scheme.equals("https")) {
        uri = getIntent().getData();
        remoteUri = true;
    }

    // reset intent
    setIntent(new Intent());
    processURI(uri, remoteUri);
}

Then in my processURI() function I do all the work and I finish with by displaying a popup telling the user the app will now restart. Then I call system.exit(0);

It works fine but the app is reopened automatically on the same Activity with the original intent even though I reset it before... how can I avoid this ?

user1026605
  • 1,633
  • 4
  • 22
  • 58
  • Not an answer, but you should not use system.exit() – Simon Feb 14 '15 at 16:58
  • Why is that ? I want to shutdown the app, and there's no other way to do that. What I want is just to get rid of the original intent when the app restarts – user1026605 Feb 14 '15 at 17:00
  • Use finish() on the activity. Why do you want to "shutdown" the app? Do you shutdown a website? It screws up Androids memory management when you exit. – Simon Feb 14 '15 at 17:04
  • I meant 'restart' because after having replaced the app current database and settings, I NEED it to be restarted (it has background services). Finishing the activity won't help – user1026605 Feb 14 '15 at 17:05
  • It's a shame you didn't add that information in the question. Would have saved time. – Simon Feb 14 '15 at 17:28

1 Answers1

0

See this answer for how to restart your app.

From the linked answer:

Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(
     getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

Edit: try;

 getActivity().finish();
 System.exit(0);

Also, calling recreate() will restart the current activity.

See this answer also.

Community
  • 1
  • 1
Jonas Czech
  • 12,018
  • 6
  • 44
  • 65