Data Storage Overview
Activity State
Saving and Retrieving Instance State
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean("loaded", true);
outState.putString("sortByChoice", sortByChoice);
super.onSaveInstanceState(outState);
}
Loading data
Saving Data
public void onActivityCreated(Bundle outState) {
int nextPage = savedInstanceState.getInt("nextPage");
super.onActivityCreated(outState);
}
Shared Preferences
Shared Preferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
String sorting = prefs.getString("testPref","defaultValue");
Loading data from Preferences
Writing to Preferences
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(c);
SharedPreferences.Editor spe = sp.edit();
spe.putInt("testPref", "helloworld");
spe.apply();
SQLite Database
Data Sharing and Retrieval
Content Providers
Content Resolver
CONTENT_URI= "content://com.example.project.healthcareprovider/nurses/rn"
Cursor c = getActivity().getContentResolver().query(CONTENT_URI,null, "movie_id =?",new String[]{movie.getId()+""},sortOrder);