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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With