Peanut
Peanut

Reputation: 2136

Detecting android Idle

I have a (somewhat) simple question about android.

I have some classes that contain some static data accessible via static methods. I do this so I can access my data wherever i need to without needing to pass the data every which way.

Anyway, when I run my app, then I 'close' it by hitting the home screen button, then come back after say 20 minutes, I receive some null pointer exceptions from that static data.

Other than testing each data whenever OnFocus is called, is there any way to detect that we are now bringing the app back into focus? Perhaps we can 'restart' the app when appropriate?

Thanks

Upvotes: 2

Views: 700

Answers (1)

Zack Marrapese
Zack Marrapese

Reputation: 12080

Within an activity, you can override public void onResume() to find out when it is being brought back.

As for the static data, you can't easily control garbage collection. You should be able to put whatever data you need for initialization into the static block, right? If that's not possible, consider using a singleton; That way, nothing outside of that class needs to know anything about actual data initialization.

Upvotes: 2

Related Questions