Search code examples
javaandroidforceclose

Force close app as in a settings by code


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


Solution

  • 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());
        }
    });