-4

My app has 10 activities, each activity has some editText submit button and one listview, when the user clicks on submit button I want to add the value of editTexts into listview. I also want to save those values so that when user reOpen app he/she can access his previous data.

I tried to save those values in sharedPreferences but it is not working with more than 1 activity.

I have also thought to save those values in sqlite database but it is very long operation

ANY Solutions....

Ronak Thakkar
  • 2,515
  • 6
  • 31
  • 45
Abhishek
  • 53
  • 1
  • 5
  • 1
    Actually SharedPreferences work with more than one Activity fortunately. You need to call getSharedPreferences() as explained in the doc (https://developer.android.com/training/basics/data-storage/shared-preferences.html). But it depends on how many data you want to store. Otherwise yes, an SQLite database could be a better idea. – Eselfar Jun 02 '17 at 09:16
  • Have a look on this: https://developer.android.com/training/basics/data-storage/shared-preferences.html – Ronak Thakkar Jun 02 '17 at 09:17
  • source code ???? which you write for this – MPG Jun 02 '17 at 09:17
  • both shared preference and Sqlite database will work properly just need to implement correctly. If you want any help provide git repository or code snipped – Mukesh Y. Jun 02 '17 at 09:21

1 Answers1

0

This sounds like a great time to get familiar with SQLite. It isn't that hard and there are great guides. So head over to https://developer.android.com/training/basics/data-storage/databases.html and read up on it.

Or you set up your own storage solution and write data to file (this will probably be more time consuming then using SQLite). This includes using file input and output streams and some way of parsing the data you want to save.

You can read more here: https://developer.android.com/training/basics/data-storage/files.html

If objects are serialize that might help making storage easier. ArrayList is serialize for example, however List isn't so watch out for that. Or make your own serialize class.

nios
  • 130
  • 12