Android Application kill, restart, restart, Method

Source: Internet
Author: User

Android Application kill, restart, restart, Method

1. Get the current process id and call the shell command to kill the process.

Int pid = android. OS. Process. myPid ();

String command = "kill-9" + Process. myPid ();
Try {
Runtime.getruntime(cmd.exe c (command );
} Catch (IOException e ){
// TODO Auto-generated catch block
E. printStackTrace ();

}


2. Call the system method to kill the process,

Android. OS. Process. killProcess (android. OS. Process. myPid ());

3. Get the package name and restart the application

ActivityManager am = (ActivityManager) getSystemService (ACTIVITY_SERVICE );
Am. restartPackage ("com. android. nfc ");


4. Call the system interface to exit the application.

System. exit (0 );


5. Restart the activity of the application.

Intent k = mContext. getPackageManager ()
. GetLaunchIntentForPackage ("com. android. nfc ");
K. addFlags (Intent. FLAG_ACTIVITY_CLEAR_TOP );
MContext. startActivity (k );

6. Restart the application

ActivityManager am = (ActivityManager) mContext. getSystemService (mContext. ACTIVITY_SERVICE );
Am. restartPackage ("com. android. nfc ");

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.