Reputation: 3079
I am making my first android app. I want to save an array of strings in one activity and then in second activity i want to show those strings as a list. I am using android platform 2.2 with API 8 So i can not use putStringSet(). Is there any way to save my data as a text file in my app? Then may be i can just add a new line in that file whenever user adds a new string. And while making list view i can parse it on basis of new line and make string array. Thanks for your help.
Upvotes: 2
Views: 433
Reputation: 1365
Why are you using files for that? Just check sharedPreferences and sqliteDb It may work for you..shared preferences are easy to handle
Upvotes: 0
Reputation: 16354
Use File Handling. Easy to use for beginners and efficient for your purpose.
http://developer.android.com/guide/topics/data/data-storage.html#filesInternal
Upvotes: 3
Reputation: 2126
There is a method putStringArrayListExtra("id", ArrayList list)
in Intent to use before starting it. Then in the launched Activity from the Intent, use getStringArrayList("id")
.
For example:
Intent intent = new Intent(MainActivity.this.getApplicationContext(), NewActivity.class);
intent.putStringArrayListExtra("id", yourArrayList)
MainActivity.this.startActivity(intent);
Then on NewActivity onCreate() method
ArrayList<String> list = getIntent().getExtras().getStringArrayList("id");
Upvotes: 2
Reputation: 697
But you can use putStringArray, or putStringArrayList wrapped into a Bundle.
Bundle are passed via Intents.
-> http://developer.android.com/reference/android/os/Bundle.html#putStringArray(java.lang.String, java.lang.String[])
Then, if you want to save it as a file, then you have to use this method : http://www.java-forums.org/advanced-java/13852-saving-arraylist-file.html
But i think you prefer pass the String list directly.
Upvotes: 0