Exit Android Application

I want to exit an Android application. Just put the quit button that kills my application.

I know I should not do this. I know this is not an OS philosophy.

If you know how to do this, pls share.

I have many open actions in the application, so "finish ()" will not do the job.

Thank you for the information. Danail

+3
source share
3 answers

Your answer helped me, Pentium10, but I needed to do one more thing:

I had to clear all my previous actions with

Intent i = new Intent ();

i.setClass (this, FirstActivity.class);

i.setFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP);

startActivity (i);

: , FirstActivity, . ( , FirstActivity). , , FirstActivity.

+5

Way One

android.os.Process.killProcess(android.os.Process.myPid())  

System.exit(0);  
+6

Close all previous steps as follows:

    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("Exit me", true);
    startActivity(intent);
    finish();

Then, in the MainActivity onCreate () method, add this to complete MainActivity

    setContentView(R.layout.main_layout);

    if( getIntent().getBooleanExtra("Exit me", false)){
        finish();
        return; // add this to prevent from doing unnecessary stuffs
    }
+1
source

Source: https://habr.com/ru/post/1748303/


All Articles