Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force-stop the application programmatically in Android

I want to force-stop an application from my Android app, (Instead of doing manually like apps-force->stop). How to achieve this?

I used:

android.os.Process.killProcess(android.os.Process.myPid());
system.exit(0);

It crashes.

like image 949
R KiranKumar Avatar asked Oct 28 '25 17:10

R KiranKumar


1 Answers

android.os.Process.killProcess(android.os.Process.myPid()); this code is correct and best one. If you need more information Refer link as How to close Android application? and Process.

You can also try this code

Intent intent = new Intent(yourCurrentActivity.this, yourNextActivity.class);  
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);  
android.os.Process.killProcess(android.os.Process.myPid());

You start an activity, and then close current activity.

like image 182
Sekar Avatar answered Oct 31 '25 08:10

Sekar