Frage

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?

War es hilfreich?

Lösung

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();  

Andere Tipps

This may helps you

This one is FirstActivity

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

eg: And secondActivity if you want to send back data

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

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

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

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top