Hello everyone I'm getting pnr status using json parsing. I'm fine with this but now I want to save result to offline means when the user once got pnr status using his pnr number once he click on save button then the result should save to offline so that he can see the status without internet. Please anyone help me. Sorry for my english. Thank you.
Asked
Active
Viewed 97 times
2
-
you can use shared preference or sqlite for that. – Pramod mishra May 19 '16 at 05:13
-
thank you I used shared preference to save json data. but it always displaying last searched pnr number result. – user7788 May 19 '16 at 05:15
-
Can you please add the code you used to get the PNR status – Pravin Ajaaz Oct 27 '16 at 08:37
2 Answers
1
you can use SharedPreferences for this.
Store your Data in SharedPreference,
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
editor.putString("PNR_STATUS", "value");
editor.commit();
Get Data,
SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
String pnStatus = prefs.getString("PNR_STATUS", "default_value");
if you want to maintain list of all previous pnr status, you can maintain list of all pnr status in Arraylist and retrieve it when needed.
for store and retrieve arraylist in sharedPrefrences you can use this
-
thank you I used shared preference to save json data. but it always displaying last searched pnr number result only – user7788 May 19 '16 at 05:17
-
-
yes I am saving searched PNRs in listview. So when I click any PNR number from listview it should get selected PNR number result in offline. – user7788 May 19 '16 at 05:22
-
for that you can maintain the arraylist of all the searched pnr status and store that array in SharedPreferences.. and retrieve that stored array list from SharedPreferences and you can display it when internet is not available. refer link in my updated answer. – Tejas May 19 '16 at 05:26
-
1Thanks to all. I have used database to store all pnr values and retrieved while fetching result – user7788 May 25 '16 at 05:23
0
Use any of the listed ORM .
Create a table with Time as a primary and PNR status with some user related information.

Madhukar Hebbar
- 3,113
- 5
- 41
- 69