KarthikSurya
KarthikSurya

Reputation: 21

Application values get removed in android

I have written the code like below extends application, in my app even though my app is running in background some time the value changed as null or empty.

While app loads from background to foreground some time the values are not available. It's happening while app is in background for 15mins - 30mins

public class AppState extends Application {

    public static String UName= "Test";
    public static String Password = "Test@123";

    public static int SLIMIT = 0 ;
    public static String iTemname = "Item";

}

Upvotes: 2

Views: 100

Answers (1)

Ali Reza Dehdar
Ali Reza Dehdar

Reputation: 2351

Android life cycle can be a little annoying to deal with.

When your application process is destroyed the static members will lose their values. So if you want to persist information, use shared preferences.

https://developer.android.com/guide/topics/data/data-storage.html#pref

Upvotes: 1

Related Questions