I managed to create an instance variable class in my android app in order to save the visibility state of a bunch of ImageView
. Is there anyway to save this variable permanently using SharedPreferences
or something? I need to load the states even if the user restarts the app.
ImageState.java
public class ImageState {
//some variables here
public ImageState(Context context, int[] imageId, int space){
//blah blah...
}
public void saveState(){
//saving visibility to shared preferences
}
public void loadState(){
//loading state
}
}
MainActivity.java
public void save(View view){
//initializing variables here
//creating ImageState
ImageState imageState = new ImageState(this, ids, count);
imageState.saveState();
}
public void load(View view){
if(ImageState!=null) ImageState.loadState();
}
How can I save imageState
?