Guilherme
Guilherme

Reputation: 7949

Recover static variables after app return from backgroun

My app has a class that extends Application and another class which is an API to get data from the Internet using a singleton pattern.
When the Application class loads, onCreate() will instantiate the singleton to be used throughout the app.

At a certain point, the user my request a transportation route, which will cause Maps to load and send my app to background.
If the user return to the app soon enough (ie, the app hasn't been fully terminated yet), all the static variables from the singleton are now null.

What is the proper way to save those variables before going to background and retrieve them back after returning to foreground?

Upvotes: 0

Views: 111

Answers (1)

Divers
Divers

Reputation: 9569

Take a look on SharedPreferences. Use it in onPause method of activity.

Upvotes: 1

Related Questions