-1

im lookin a way how to force close app like when using `

Settings -> application->installed->MyApp ->Force close.

` It's possible? im just tested threed and put there Toast , and it's make toast always while app not force closed. I want when i leave from my app - just Fully close my app. :) please

Peter
  • 2,480
  • 6
  • 39
  • 60

3 Answers3

0

Try this -

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

It will destroy the app.

Alternatively, you can do this -

Intent homeIntent = new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory( Intent.CATEGORY_HOME );
homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(homeIntent);

This will take you to the home screen and the current processes will be paused.

Confuse
  • 5,646
  • 7
  • 36
  • 58
0

You can use something like this:

final Button mClose = (Button) findViewById(R.id.force_close);
mClose.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {           
        System.exit(0);
        //or you can use 
        //android.os.Process.killProcess( android.os.Process.myPid());
    }
});
Sagar Pilkhwal
  • 3,998
  • 2
  • 25
  • 77
-1

This question was already discussed here : How to quit android application programmatically

You should let the OS decides when the resources should be freed or not. Using all other methods can lead you to not stable state like : not saving data, not calling onStop(), etc... You should be really careful forcing the app to be closed.

You can have some details about closing your application yourself here : Is quitting an application frowned upon?

Community
  • 1
  • 1
mithrop
  • 3,283
  • 2
  • 21
  • 40