0

I have an application that sometimes hits the OutOfMemoryError due to processing a large number of bitmaps. I'm catching the error and I want to display a dialog to the user letting them know that they need to kill some background tasks to free up memory. It would be nice to have a button that opens up an application that does this.

Is there a way to start an Intent that launches:

  • Applications Manager > Running Processes (so the user can force stop some tasks)

  • Or even better the option to choose from any apps the user might have installed that allow you till processes (eg: Advanced Task Manager)

An even better option would be to automatically clear up background activities but I doubt this is possible.

nedaRM
  • 1,837
  • 1
  • 14
  • 28

2 Answers2

1

I have an application that sometimes hits the OutOfMemoryError due to processing a large number of bitmaps.

This means that your own process' heap cannot allocate blocks for your bitmaps.

I want to display a dialog to the user letting them know that they need to kill some background tasks to free up memory

Even if it were possible for you to bring up such a dialog, it would be a complete waste of your time and your users' time. The existence, or lack thereof, of other apps' processes will do nothing about the heap in your own app.

Is there a way to start an Intent that launches

I am not aware of such an Intent.

An even better option would be to automatically clear up background activities but I doubt this is possible.

You are welcome, even encouraged, to finish() your own activities when you no longer need them, to free up memory in your heap that the rest of your app can use.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I don't mean my own activities, I mean other application running in the background. Whenever I hit this error, I go to Advanced Task Manager and close all the apps running, return to my application and it runs fine. I want to direct the user to do the same thing when they hit this problem. I'm aware that this is bad practice but this only happens on phones that have a lot happening in the background. – nedaRM Sep 10 '13 at 00:28
  • 1
    @user2045570: "Whenever I hit this error, I go to Advanced Task Manager and close all the apps running, return to my application and it runs fine" -- you are welcome to believe whatever you want. You are also welcome to publish a reproducible test case that demonstrates this behavior. You are also welcome to use MAT for diagnostics, and use other bitmap-management techniques, to find a real solution for your problem. – CommonsWare Sep 10 '13 at 00:33
  • 1
    @user2045570: You are also welcome to read the documentation on this topic: http://developer.android.com/training/displaying-bitmaps/manage-memory.html http://developer.android.com/training/displaying-bitmaps/index.html – CommonsWare Sep 10 '13 at 00:34
  • @user2045570: I would also suggest http://stackoverflow.com/questions/10677850/android-understanding-heap-sizes http://android-developers.blogspot.com/2011/03/memory-analysis-for-android.html – CommonsWare Sep 10 '13 at 00:37
  • Thanks for the recommendations. Iv'e actually implemented most of these solutions. The problem is I cannot re-size the bitmaps as they are map tiles, and I can't recycle them either because the boss wants the map tiles downloaded to be kept in memory. I'll try and find a better solution for the problem. Just want a temporary one to show the boss and keep him happy. – nedaRM Sep 10 '13 at 03:34
1

This might not solve the issue or suggest what you are looking for. But as you are loading large bitmaps and the relevant OOM exception, thislink is worth a read

To load the apps screen in the settings, this is the close that you can get

 startActivity(new Intent(Settings.ACTION_APPLICATION_SETTINGS));

But, why should one close other apps to get your app working. Users would uninstall your app than messing up with your apps mate!

prijupaul
  • 2,076
  • 2
  • 15
  • 17
  • Thanks. That's what i'm looking for. Iv'e everything that has been suggested to handle the OOM exception but the it still shows up on my Boss's phone, and only on his phone, as he has every app you could think of installed and running. And so he sees that problem and wants this solution. I know it is a bad one but I am just a programmer. – nedaRM Sep 10 '13 at 03:32