Android Global Variables Not Persistent

I created a class that extends the application to store the variables that I want to get from several actions.

public class MyApplication extends Application 
{
private String fbId, firstName;
private long expires;

@Override
public void onCreate() 
{
    super.onCreate();
}

public String getFbId() 
{
    return fbId;
}

public void setFbId(String fbId) 
{
    this.fbId = fbId;
}

public String getFirstName()
{
    return firstName;
}

public void setFirstName(String firstName) 
{
    this.firstName = firstName;
}

I can access these variables and set these variables when I first run the application. As soon as I leave and restart the application, it will set my values ​​to zero, any suggestions as to why this could happen?

+3
source share
3 answers

If you do not store your data in a repository (which does not have to be a database, maybe a flat file, SharedPreferences, or something else), then it is not permanent.

You must use to maintain such persistent data. SharedPreferences

SharedPreferences , . SharedPreferences : booleans, floats, ints, longs strings. ( ).

+4

. , , RAM/Heap.

,

    • (,.txt)
    • ( .csv)
    • Sqlite ( Android)
    • RMS ( Java ME, BlackBerry)
  • Languag
    • SharredPreference

, .

0

You may want to save the data if you need it when you return. You can use a different storage medium for the same as SharedPreference, Local Files, sqlite, etc. Please contact here

0
source

All Articles