This is my problem, I have the main view which only shows one button, pressing this button another view is shown. This view has only another button, when this button is push this current view finishs and the control backs to the previous view.
To show the second view I use startActivityForResult, I put the code here.
private void startNewview() {
Intent it = new Intent(getApplicationContext(), newView.class);
startActivityForResult(it,VIEW_ID);
}
The view called only has a button event, here is the code
Button b = (Button) findViewById(R.id.close);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
setResult(RESULT_OK);
finish();
}
});
And finally, the method onActivityResult in the main view, here is the code
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == VIEW_ID && resultCode == RESULT_OK) {
tv = (TextView) findViewById(R.id.tv);
tv.setText("The result ok is here :)");
}
}
The problem is resultCode always is 0 = RESULT_CANCELED and I do not know how to solve it, can anyone help me?
Thank you very much!
here,
@Override
public void onBackPressed() {
setResult(Activity.RESULT_OK);
finish();
}
does work to return(RESULT_OK) by pressing the BACK button. Do NOT call
super.onBackPressed()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With