0

I have a countdownTimer ProgressBar in my activity , I need to save the timepassed and few arraylists if the user destroys the activity, so that when it is recreated within the countdownTimer span, I can start from where it was stopped. But im Confused to save in sqlite or shared preferences? I searched and saw shared preference as better option but how can I save arraylist in shared preference??

D Agrawal
  • 471
  • 4
  • 15
  • 1
    use gson library to save arraylist in shared preferences – Vivek Mishra Mar 30 '16 at 07:03
  • Any other way. Im not using Gson at the moment. and wouldnt like to include the library just for this. Can u rather help me and tell how to convert arraylist to Json String – D Agrawal Mar 30 '16 at 07:04
  • 1
    Yes, you can save arraylist on `SharedPreferences` but remember, if a user clear app data or have a root device, he/she can see your data or delete it. – Aspicas Mar 30 '16 at 07:05
  • 1
    *wouldnt like to include the library just for this* do it anyway. Don't reinvent the wheel. Use what is out there. Gson is a small library – Tim Mar 30 '16 at 07:05
  • 1
    save them in a file then which would be more typical to do – Vivek Mishra Mar 30 '16 at 07:06
  • I agree with @TimCastelijns, *Don't reinvent the wheel*, but you can use `HashSet` instead of `Gson Library` – Aspicas Mar 30 '16 at 07:08
  • @Aspicas : so u suggest sqlite? But how would i shift arraylist to db and back again? – D Agrawal Mar 30 '16 at 07:10
  • 1
    Beware that there are instances when `onDestroy()` won't be called. – Jyotman Singh Mar 30 '16 at 07:12
  • 1
    mmm... `sqlite?`... I don't know if you need store a important data... you must decide if it's important and choose the best option...anyway, if its a important data and your user had a root device, he/she can see you database also.. Encrypt your data too on database if it's a important data. – Aspicas Mar 30 '16 at 07:14
  • 1
    Note that wiping app data also removes any sqlite or other database, so that's no valid argument – Tim Mar 30 '16 at 07:18
  • 1
    @Aspicas : Thanks for the help. 2 – D Agrawal Mar 30 '16 at 07:18
  • Yeah... of course, if an user clear app data, he/she removes all databases... – Aspicas Mar 30 '16 at 07:22

0 Answers0