Reputation: 163
Can anybody explain to me one thing?
I'm trying to use OnPause() for my application. When a user is choosing for the other app and my app no longer visible OnPause() of my app starts perfectly. I'm trying to use in OnPause() some method, for example, to save some data. I noticed that in OnPause() I can operate with some public variables of my app (to assign data, to retrieve data and so on), but I have a problem with my public string array filled out in OnCreate.
If I'm trying, for example, to do: String temp_str = my_array[1]
in OnPause(), my app crashes with an explanation like "Source code does not match the bytecode". Can anyone make a hint about why this happens: public variables are being used fine in OnPause(), but with the public arrays I have a problem?
Upvotes: 0
Views: 48
Reputation: 523
From the Android Developing Guide, in the onPause()
lifecycle section found here:
onPause() execution is very brief, and does not necessarily afford enough time to perform save operations. For this reason, you should not use onPause() to save application or user data, make network calls, or execute database transactions; such work may not complete before the method completes. Instead, you should perform heavy-load shutdown operations during onStop()
So, the best solution is to move your method calls to the onStop()
application status. onStop()
gets called after onPause()
, when the application is no longer visible or whenever you are about to completely close your app.
Upvotes: 1