Transferring data from one activity to another in Android

Possible duplicate:
How to transfer value from one action to another on Android?

I have an activity with a list of names and their bodies (content) (example list6 from ApiDemos). And I have activity where I add a note. When I click the Add button, I want the title of my note to appear in the list. Same thing with the body. The problem is that the List activity has two String [] arrays with predefined hard-coded headers and bodies. What should I do to add my own proper names with content instead of these hardcoded values? I know I have to use intentions with startActivityForResult, but that is probably all I know ...

+6
android
source share
2 answers

You have two options:

1) make a listview and two arraylists static

Thus, you can use the same instances from the action with the add button and change the list as:

FirstActivity.listTitlesArrayList.add(listTitleString); FirstActivity.listDescriptionArraylist.add(listDescriptionString);//this is probably your note FirstActivity.listView.invalidateViews(); 

2) if you want to use the intent:

going to ListActivity pass by .. data

 intent.putExtra("Title", listTitleString); intent.putExtra("Content", listDescriptionString); startActivity(intent); 

and restore it in second use:

 title= getIntent().getExtras().getString("Title"); 

... etc.

+32
source share

There are several ways to share data between actions .

In your case, perhaps the easiest way is to link to a list in the application. This answer sums up: Providing data obtained in one action for all activities

+1
source share

All Articles