Killing background apps

I only know C# programming language and I create games in unity and my projects get completed by today and I also created some app with MIT app inventor. I need one extension to close all background app like optimizing the android device. I tried to write code to stop background apps below

List ApplicationInfo> packages;
PackageManager pm;
pm = getPackageManager();
//get a list of installed apps.
packages = pm.getInstalledApplications(0);

I can explain above code. So, here a list is created and a list stored package name of all installed app in a android device

ActivityManager mActivityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
for (ApplicationInfo packageInfo : packages) {
if((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM)==1)continue;
if(packageInfo.packageName.equals("mypackage")) continue;

now above code just call activity manger to kill background app by list or we can replace the list by an package name

I dont know Java or any one can tell what kind of library are needed for this extension or somebody can create this extension ?

any help is appreciated :slightly_smiling_face:

Android no longer allows it.

but app like killapp or task killer can do these things and is there an way to do force stop like an other do in play store.


yeah you are right android not allow it

i found new example to do this
How to force kill a service programmatically in Android | RevealedTricks4U - Latest and Revealed Tricks For U


how we can execute this code of line
thank very much for interest

This will kill your own app/service.

do you know how to do ? like an example

Maybe you can hava a look here:

Also check this section: