Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to close/stop running application on background android

Tags:

android

i want to close or stop running application when i exit from main screen means very first layout of application when i press back button in android. i use this but my application is running on background

        @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
       // Splash screen view
        setContentView(R.layout.splash);
        }


 **public void onDestroy()
  {
 super.onDestroy();
 System.runFinalizersOnExit(true);
 System.exit(0);
    }**
like image 435
shyam Avatar asked Dec 13 '22 09:12

shyam


1 Answers

get the process ID of your application, and kill that process onDestroy() method

@Override
public void onDestroy()
 {
    super.onDestroy();

    int id= android.os.Process.myPid();
    android.os.Process.killProcess(id);
 }
like image 105
Mohammed Azharuddin Shaikh Avatar answered Feb 24 '23 13:02

Mohammed Azharuddin Shaikh