Search code examples
androidmemory-managementsubactivity

multiple sub-activities that causes low memory


My app requires the user to go through multiple pages of input (signing up process). As the user goes deeper into the signup, I have to keep the data intact till the user clicks on "finish". This process involve activity calling sub-activities and those sub activities calling another sub-activity.

The flow is like this: Main -> Sub-Activity (part 1 of signup) -> Sub-Activity (part2) -> Sub-Activity (part 3).

The problem here is, I'm having a low memory warning from the logcat and various processes are being killed as the user goes in deeper into the app. I already tried to save on-hand memory by not passing custom objects among activity but by storing them into mysqllite and retrieving them when needed. One more point to add is, I'm not dealing with images and controls used are just textviews, editviews and spinners.

My question is, is it common to have low memory issues when there are multiple sub-activities chained? How do I go about it to free up memory? Does custom controls uses significantly more memory than preset controls? (One of my hunch)

*Edit* I found the reason for the low memory issues. It has nothing to do with sub activities. The culprit is the custom controls i'm using. I did a test by using the preset controls instead and the overall performance of the app improve drastically. I no longer have the low memory warning and everything works smoothly now.


Solution

  • I dont think it is common to have memory issues with subactivities.. i have used a tab host with 5 tabs and 3-4 activities in each plus complicated methods http calls and image adapters and there were no issues (this way the activites dont call the onDestroy method but just call onPause and then onResume). try having less global variables ex. just reference the views and get their data when you press the next button to pass to other activity or something like that so that the garbage collector collects the trash. remove some of the references when onPause is called and then if you need them again just reference them again (maybe on onResume)