Possible Duplicate:
How to pass a value from one Activity to another in Android?
I have an activity with a list of titles and their bodies(content) (list6 example from ApiDemos). And I have an activity, where I add a note. When I click on "Add" button, I want the title of my note to appear on the list. Same with body. The problem is, that in List activity there are two String[] arrays with predefined hard-coded titles and bodies. What should I do to be able to add my own new titles with a content instead of having these hard-coded values? I know I must use intents with startActivityForResult, but that's probably all I know...
We can send the data using the putExtra() method from one activity and get the data from the second activity using the getStringExtra() method.
The easiest way to do this would be to pass the session id to the signout activity in the Intent you're using to start the activity: Intent intent = new Intent(getBaseContext(), SignoutActivity. class); intent. putExtra("EXTRA_SESSION_ID", sessionId); startActivity(intent);
Android uses the action ACTION_SEND to send data from one activity to another, even across process boundaries. You need to specify the data and its type. The system automatically identifies the compatible activities that can receive the data and displays them to the user.
You have two option:
This way you can use the same instances of it from the activity with add button and modify the listview as:
FirstActivity.listTitlesArrayList.add(listTitleString);
FirstActivity.listDescriptionArraylist.add(listDescriptionString);//this is probably your note
FirstActivity.listView.invalidateViews();
while going to the ListActivity pass data by..
intent.putExtra("Title", listTitleString);
intent.putExtra("Content", listDescriptionString);
startActivity(intent);
and to recover it in second activity use:
title= getIntent().getExtras().getString("Title");
...and so on..
There are several ways to share data between activities.
In your case probably the easiest way is to have a reference to list in Application. This answer summs it up nicelly: Making data obtained in one activity available to all the activities
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With