2

I have 2 activities first details activity and second activity page is confirmationPage,Once i confirm it should come back to first page,how should i handle this scenario?

Is it possible between activities,instead of using fragments?

Rakesh
  • 14,997
  • 13
  • 42
  • 62

3 Answers3

6

you have to use startActivityForResult(); method when you start the secondActivity.

and you also have to implement the onActivityResult() method.

Here is the code for first Activity..

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == 1) {
            Bundle extra = data.getExtras();
            String ID = extra.getString("NameKey").trim();
             // do your code here.
            
        }
    }

Code in the second Activity..

add the code on confirm click button.

  Intent i = new Intent();
  Bundle extra = new Bundle();
  extra.putString("NameKey", KeyValue);
                
  i.putExtras(extra);
  setResult(1, i);
  finish();
Vova
  • 956
  • 8
  • 22
Preet_Android
  • 2,332
  • 5
  • 25
  • 43
2

Start confirmationPage for result by startActivityForResult(intent, requestCode),

Here is a complete example (http://www.vogella.com/articles/AndroidIntent/#usingintents_sub)

Sadegh
  • 2,669
  • 1
  • 23
  • 26
1

I believe calling finish() is the easiest way to back out of an activity. It should return to the previous one similar to if you hit the back button.

edit: Although, as Sirlate mentioned, startActivityForResult is probably your best bet if you wish to return data.

Jon
  • 1,398
  • 9
  • 14