0

I have some data on many static atributes on my classes. Then, when I call startActivityForResult to pick an image (from gallery or camera) and handle the results, the static values just are empty.

I know saveInstance from activity and things like that, but that data are not activity related. It's set in another class in static way. Like we can see here and here the static variable just must be erased when the app was destroyed.

Can someone help me with that?

Community
  • 1
  • 1
Tiago Gouvêa
  • 15,036
  • 4
  • 75
  • 81

1 Answers1

1

Then, when I call startActivityForResult to pick an image (from gallery or camera) and handle the results, the static values just are empty.

Your process was terminated while your UI was in the background, to free up memory for other processes. This is fairly common when invoking a third-party camera app.

Static data members are only a cache. If you want to have data survive process termination, store that data in a database, SharedPreferences, or some other form of file.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks @CommonsWare. I put a breakpoint in onDestroy on that activity and it never called.. it's normal? – Tiago Gouvêa Feb 23 '15 at 10:41
  • 1
    @TiagoGouvêa: `onDestroy()` is not guaranteed to be called. That being said, I would have expected it to be called in this case, at least for a device with reasonable specifications in terms of system RAM. – CommonsWare Feb 23 '15 at 12:46
  • Ok CommonsWare, you are right. On emulator the app don't was destroyed, but in my real device Galaxy SIII, when the gallery opens the destroy happen and all my static values are lost. I thought that just activities were destroyed, but, it that case it destroy everything. :( I solve saving it on onSaveInstanceState and restore at onRestoreInstanceState and all ok now. – Tiago Gouvêa Feb 23 '15 at 13:20