Rayhanul Masud
Rayhanul Masud

Reputation: 59

Want to clean unused memory from ram of unrooted android device programatically

I want to make a ram booster app. For two months long, i am trying to clean unused data from the ram of android device programmatically. Though through searching the internet, I have found codes for deleting the unused data of itself, I cannot find any code directly for cleaning the ram unused data. I also have used some codes from the internet,but did not get any result. I want to get suggestion how can i do it. Here is a code i have tried. Using this code, i have seen that after running the app, it cleans some memory from the app, but after a few seconds the ram memory again fills up .

List<ApplicationInfo> packages;
        PackageManager pm;
        pm = getPackageManager();

        packages = pm.getInstalledApplications(0);


        ActivityManager mActivityManager = (ActivityManager)getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);

        for (ApplicationInfo packageInfo : packages) {
            if((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM)==1)continue;
            if(packageInfo.packageName.equals("mypackage")) continue;
            mActivityManager.killBackgroundProcesses(packageInfo.packageName);
            // mActivityManager.restartPackage(packageInfo.packageName);
       }

Upvotes: 4

Views: 5485

Answers (3)

krishnamurthy
krishnamurthy

Reputation: 1604

just place

    System.runFinalization();
    Runtime.getRuntime().gc();
    System.gc();

In the ondestroy method of main activity.

Upvotes: 1

Praveen Thirumurugan
Praveen Thirumurugan

Reputation: 1077

You need not worry about the memory as Android knows which apps to kill or suspend when there is need for memory for current stack of applications. And modifying the usage of your app can be done using finish() method which will close the activity for which the finish method is called.

Upvotes: 0

Bredman
Bredman

Reputation: 21

If you make a RAm booster app it would pay to first investigate how android works. Android RAM is supposed to be filled - or at least a high part. That makes it so snappy to switch between apps.

Android will kill old processes itself (freeing up RAM) automatically when it needs to. If you're seeing apps come back after a couple of minutes, it's because the framework is trying to repopulate the RAM.

Cleaning RAM on windows is good: if it's full your pc.gets slower Cleaning RAM on Android is bad: if it's empty it needs to reinitialise all processes when started.

Upvotes: 2

Related Questions