-1

I have 3 activities : activity "valider" as 1st activity and the second is activivty "connexion" and finally the inscription activity , i hope to pass from 1st==> second==> third and viceversa from third==> second==>first activity. Please someone can help me?

2 Answers2

0

There are multiple ways to share data with different activities your question is repeated please check this: What's the best way to share data between activities?

Community
  • 1
  • 1
Sanju
  • 663
  • 9
  • 20
0

To pass data in the First:

void send() {
Intent intent = new Intent(this, Second.class);
intent.putExtra("NAME",some_value);//your data
startActivityForResult(intent, yourSomeId);// if you want to retrieve callback data later
startActivity(intent);//or simply
}

in the Second in

@Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    Bundle extras = getIntent().getExtras();
    if(extras == null) {
        yourData = null;
    } else {
        yourData = extras.getString("NAME");
    }
}

to send data back:

charge data in the second activity:

void back() {
    Intent intent = new Intent();
    intent.putExtra("NAME", yourdata);
    setResult(RESULT_OK, intent);
    finish();
}

and retrieve in the First:

 @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (data == null) {return;}
    yourdata = data.getStringExtra("NAME");

  }

you can send the data to the third activity in the same way.

Vyacheslav
  • 26,359
  • 19
  • 112
  • 194