Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing an app programmatically from own app

I want to close another app opened from my app with an intent.

On my app, I create an intent to open Google Maps, but I want to close this Google Maps with a button on my app.

Is that possible?

like image 780
Chuflitas Avatar asked Nov 16 '25 11:11

Chuflitas


2 Answers

It is not possible to close the another app from your app.

It is ethically not correct and there is no official Android API as well.

like image 80
Vikasdeep Singh Avatar answered Nov 18 '25 00:11

Vikasdeep Singh


You can only close the background processes of other apps, you are no longer able to close their main activities.

Declare a permission for that in your AndroidManifest file:

<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />

In your app:

ActivityManager manager = (ActivityManager)getSystemService(Activity.ACTIVITY_SERVICE);
manager.killBackgroundProcesses(packageName);

I have used this code and it has worked for me.

Hope this can help you, thanks.

like image 44
Sheikh Hasib Avatar answered Nov 18 '25 02:11

Sheikh Hasib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!