In my application I need to launch a SelectionActivity to select one of the options. Once the option has been selected I need to refresh another list on the MainActivity.
This is the code that I use to launch the SelectionActivity:
Intent intent = new Intent(MainActivity.this, SelectionActivity.class);
startActivity(intent);
In SelectionActivity this is the code that receives the selected option an closes the activity:
selectedValue = adapter.getItem(position);
finish();
Now the application comes back to MainActivity but I don't know how to receive an event that the SelectionActivity has closed.
Thanks
Quick snippet showing use of startActivityForResult:
private static final int MY_REQUEST_CODE = 0xe110; // Or whatever number you want
// ensure it's unique compared to other activity request codes you use
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == MY_REQUEST_CODE)
ActiviyFinishedNowDoSomethingAmazing();
}
public void onClickStartMyActivity(View view)
{
startActivityForResult(new Intent(this, GameActivity.class), MY_REQUEST_CODE);
}
More reading on getting a result from an activity.
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