1

I've 2 activities, Activity1 and Activity2.

In Activity1 i've a EdiText and ImageView. When button is clicked Activity2 is started.

In Activity2 i've a listview. It contains Image and TextView.

I have displayed the data retrieved from listview image and textview in Activity2 in the imageview and editext resp in Activity1 . Now i made some changes in the editext and imageview in Activity1 and I need to pass this changes again to the listview image and text in Activity 2.

can someone help me with the code to make this work?

Lokesh
  • 5,258
  • 4
  • 26
  • 43
  • Now, you have stated what you need. Please show some releavant code you have been working on. It could help us who are trying to help you. – Augustus Francis Sep 23 '13 at 11:21

3 Answers3

1

Better idea is to use startActivityForResult.

It similar problem to this: How to manage `startActivityForResult` on Android?

Community
  • 1
  • 1
TommyNecessary
  • 1,367
  • 1
  • 13
  • 19
0

In your current activity1, create an intent

Intent i = new Intent(getApplicationContext(), Activity2.class);
i.putExtra(key, value);
startActivity(i);

then in the other activity2, retrieve those values.

Bundle extras = getIntent().getExtras(); 
if(extras !=null) {
    String value = extras.getString(key);
}
Lokesh
  • 5,258
  • 4
  • 26
  • 43
0

From your FirstActivity call the SecondActivity using startActivityForResult() method

Code:

Intent i = new Intent(this, SecondActivity.class);
startActivityForResult(i, 1);

In your SecondActivity set the data which you want to return back to FirstActivity.

eg: In SecondActivity if you want to send back data set a onclicklistener on the item and use this code:

Intent returnIntent = new Intent(); returnIntent.putExtra("image",image); returnIntent.putExtra("title",title); setResult(RESULT_OK,returnIntent);
finish();

If the user doesn't select any list item and pressed Back Button. In your MainActivity use this code.

@Override
public void onBackPressed() {
    Intent returnIntent = new Intent();
    setResult(RESULT_CANCELED, returnIntent);        
    finish();
}

Now in your FirstActivity class write following code for onActivityResult() method

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

  if (requestCode == 1) {

     if(resultCode == RESULT_OK){      
         String image=data.getIntExtra("result");
         String title=data.getStringExtra("title");
         ImageView img = (ImageView) findViewById(R.id.imageid);
         TextView txt = (TextView) findViewById(R.id.txtid);
         image.setImageResource(image);
         txt.setText(title);
     }
     if (resultCode == RESULT_CANCELED) {    
         //Write your code if there's no result
     }
  }
}//onActivityResult
Augustus Francis
  • 2,692
  • 4
  • 20
  • 32