0

Ok here is the main idea: I need a list of text (f.e. "one", "two", "three", "four", "five").

Then I will create a button (RandomButton) when onClick it will display one of the texts in random order. Say for example that I pressed the RandomButton and it popped the word "three".

I will have a second button (CheckButton) when I press it it transfer the word "three" to second activity and deletes the word "three" so it wont be sawn again. Then I press again the RandomButton and it will dislplay f.e. the word "two".

When I press the CheckButton it will transfer the word "two" above the word "three" in the second activity.

Therefore it will create a list of the words sometime.

If I close the app and reopen it the list it will be already created and the deleted words will remain deleted.

What is the best way to do this? Any ideas?

I did it already with strings but when I close the app and reopen it its like Im opening it for the first time..

1 Answers1

-1

You just need some sort of persistence layer, so the modifications you've made to the list don't go away when your app is closed. You can do this a lot of ways. You can use a Content Provider, you can do raw access to a SQLite database using SQLiteOpenHelper -- or you can do the simplest and save your string list to a file / read from file if it exists on open.

There's examples for all of these on Stack Overflow, you need to decide which you want to do and follow those examples. If you decide to go the simplest way, see How can I read a text file in Android?

Community
  • 1
  • 1
Kasra Rahjerdi
  • 2,483
  • 26
  • 42
  • With the text file I can save the strings that Im passing as a text? and then I just have to open the text? – Thanos Tokmakis Jun 29 '16 at 18:10
  • What solution you suggest? – Thanos Tokmakis Jun 29 '16 at 18:11
  • @ThanosTokmakis what sort of data structure are you using for your lists? If you had some code in your question it'd be a lot easier to give you a simpler answer :) If you're using traditional lists or arrays or something to hold onto the items, you can simply serialize that entire POJO to a file / deserialize it when reading. – Kasra Rahjerdi Jun 29 '16 at 19:00