1

I am working on app in which i have to free up some memory from ram.

private fun clearMemory(){
    try {
        val mActivityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        var packs = context.packageManager.getInstalledPackages(PackageManager.GET_META_DATA)
        for (i in 0 until packs.size){
            var pkgInfo = packs[i]
            mActivityManager.killBackgroundProcesses(pkgInfo.applicationInfo.loadLabel(context.packageManager).toString())
        }
    }catch (ex: Exception){
        ex.printStackTrace()
    }
}

Above is the code i am using but i think it cannot perform the required operation.

Alberto M
  • 1,608
  • 1
  • 18
  • 42
User
  • 31
  • 5
  • Possible duplicate of [How to clear inactive memory in Android programmatically?](https://stackoverflow.com/questions/20797338/how-to-clear-inactive-memory-in-android-programmatically) – Ricardo A. Apr 30 '19 at 12:53
  • There is any exception ocurring or some log? Didn't find any problems with your code. (you probably need to be rooted though) – Ricardo A. Apr 30 '19 at 13:16
  • https://stackoverflow.com/questions/8814696/how-to-kill-currently-running-task-in-android/8849562#8849562 – Ricardo A. Apr 30 '19 at 13:17
  • This might be the case because ram shows same data after execution of code. – User Apr 30 '19 at 13:35

0 Answers0