开发者

getting values from another page

In my app i have two Activities OpenAccount and BillAccount. On the Button Click in OpenAccount we are navigating to BillAccount. From BillAccount acticity again we are going back into previous Activity OpenAccount. Here while navigating back i want some variable values in OpenAccount. I tried by

intent.putExtra("trnxnId", trnxnId)

and to get values in OpenAccount

开发者_如何学JAVA
intent.getExtras().getString("trnxnId");

but it giver error on first load of OpenAccount since that time it doesnt have value of this variable with intent.

Please help how can we get values in this case?


You can do it in this way:

Bundle bundle=new Bundle();
bundle.putString("trnxnID",trnxnID);
it.putExtras(bundle);

And you can get it by:

it.getExtras().getString("trnxnID");


getIntent().getStringExtra("trnxnId").equals(null) ? "" : getIntent().getStringExtra("trnxnId");

try using above, it handles the case when no value is returned.


I think you should try using startActivityForResult if you are not doing that already.

In OpenAccount activity:

Where you start the BillAccount from OpenAccount:

int requestCode = 1;
Intent intent = new Intent(this, BillAccount.class);
startActivityForResult(intent, requestCode);

Implement this method in OpenAccount:

@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
  if(resultCode == RESULT_OK) {
    data.getStringExtra("trnxnId");
  }
}

In BillAccount before you finish it:

Intent intent = new Intent();
intent.putExtra("trnxnID", trnxnID);
setResult(RESULT_OK, intent);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜