I am developing an Android application and need to store some objects to the disk for some reason (with the onSaveInstanceState()
method) and then retrieve them back again (with the onRestoreInstanceState()
method) with Serialization/Parcelable.
As you might know, to make a class as Parcelable, you need to use Parceler Library or write some boilerplate code.
My problem is, that I have some objects that don't write their class. They are a 3rd party or Android-Sdk related Class. For clarity here is my code:
private FragNavController mNavController;
private MenuItem mMenuItem;
private SharedPreferences mPrefs;
@Override
public void onCreate(Bundle savedInstanceState) {
LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
setDefaultLanguage(Locale.ENGLISH.toString());
//Paper.init(getApplicationContext());
mPrefs = getPreferences(MODE_PRIVATE);
super.onCreate(savedInstanceState);
.
.
.
}
I use Parceler Library, Xstream ,icepick, paper, Gson and sharedPreferences Method, but in all of them, I fail to save some objects like mNavController
and mMenuItem
.
Has anyone faced this problem before and know the best solution to save these objects?