Reputation: 622
This is my scenario
Desired Flow in app
Step 1: A ==> B
Step 2: B ==> A
Step 3 (Required flow):
Activity A has to reload itself or call loadListView() function after Activity B exits or is closed.
onCreate(){
.......
....
btnAddClient.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent( ActivityA.this, ActivityB.class);
startActivity(intent);
}
});
loadListView();
......
....
}
Upvotes: 1
Views: 334
Reputation: 1156
Getting a result from an activity
From your Activity A, call the Activity B using the startActivityForResult() method.
int RESULT_CODE = 123;
Intent intent = new Intent(this, ActivityB.class);
startActivityForResult(intent, RESULT_CODE);
Now in your ActivityA class, write the following code for the onActivityResult() method.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_CODE) {
if(resultCode == Activity.RESULT_OK){
bool status=data.getBooleanExtra("isUserAdded");
if(status)
{
loadListView();
}
}
}
} //onActivityResult
Return back to ActivityA with status.
Intent returnIntent = new Intent();
returnIntent.putExtra("isUserAdded",true);
setResult(Activity.RESULT_OK,returnIntent);
finish();
Upvotes: 1
Reputation: 1300
Try to call loadListView()
in onStart
or onResume
methods. It will refresh the list when you come back to your activity
Upvotes: 2