Reputation: 115
I want to close another app opened from my app with intent ... On my app i create an intent to open Google Maps, but i want to close this Google Maps with Buton on my app. Is it posible? Thank you guys!
Upvotes: 4
Views: 3985
Reputation: 1
In the past, for third party Apps not designed for this, I have used:
activity.startActivityForResult(intent, requestCode);
and then done a:
activity.finishActivity(requestCode);
using the same requestCode to stop the Activity. You should receive a resultcode == RESULT_CANCELED to:
protected void onActivityResult(int requestCode, int resultCode, Intent data)
if you wish to know it finished.
It tends to produce a clunky result though.
Upvotes: 0
Reputation: 21756
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.
Upvotes: 5
Reputation: 7493
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" />
APP:
ActivityManager manager = (ActivityManager)getSystemService(Activity.ACTIVITY_SERVICE);
manager.killBackgroundProcesses(packageName);
I had used this code, that was worked for me.
Hope this can help you, thanks.
Upvotes: 3