Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SharedPreferences preferences =
- getSharedPreferences("mypref",MODE_PRIVATE);
- SharedPreferences.Editor prefsEditor=preferences.edit();
- Gson gson=new Gson();
- if(preferences.contains("counter")){
- counter=preferences.getInt("counter",0);
- prefsEditor.putInt("counter",++counter);
- }
- else{
- counter=0;
- prefsEditor.putInt("counter",++counter);
- }
- String json = gson.toJson(student);
- prefsEditor.putString("details"+counter,json);
- prefsEditor.commit();
- startActivity(intent);
- SharedPreferences mPrefs =
- getSharedPreferences("mypref",MODE_PRIVATE);
- int howMany=mPrefs.getInt("counter",0);
- Gson gson = new Gson();
- for(int i=1;i<=howMany;i++) {
- String json = mPrefs.getString("details" + howMany, "");
- Student student = gson.fromJson(json, Student.class);
- Log.e("tag","loop number"+i);
- Log.e("Tag", student.getName());
- }
- 05-23 10:45:48.212 18409-18409/com.example.com.applicationstudent
- E/tag: loop number1
- 05-23 10:45:48.212 18409-18409/com.example.com.applicationstudent
- E/Tag: suv
- 05-23 10:45:48.212 18409-18409/com.example.com.applicationstudent
- E/tag: loop number2
- 05-23 10:45:48.212 18409-18409/com.example.com.applicationstudent
- E/Tag: suv
Add Comment
Please, Sign In to add comment