Reputation: 1600
I have to go to parent activity when any list item is clicked, with setResult.
list.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Log.d("gaurav", "list is clicked");
moveToEvent();
}
});
My moveToEvent method is :
public void moveToEvent() {
Log.d("gaurav", "Move to evnet");
Intent intent = new Intent();
this.setResult(5, intent);
// this.startActivity(intent);
this.finish();
}
Using this code I am able to come back to parent activity two or three times, After that its not coming back to parent activity and refresh its own activity. I am not able to find its solution. Kindly help me in this issue
I also tried onBackPressed method but same result.
@Override
public void onBackPressed() {
// TODO Auto-generated method
Intent intent = new Intent();
setResult(5, intent);
finish();
super.onBackPressed();
}
Kindly suggest me where i am doing mistake.
Upvotes: 1
Views: 3183
Reputation: 1600
I used this to solve my problem . This code will be in parent activity.
Intent intent = new Intent(AddEvent.this, AddVenue.class);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(intent, 222);
((Activity) AddEvent.this).overridePendingTransition(0, 0);
This is the key line to solve this problem.
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
Upvotes: 0
Reputation: 13805
You have to start your ParentActivity with
Intent i = new Intent(SignUpActivity.this, UploadImage.class);
startActivityForResult(i, 1);
And then write this in your ParentActivity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
//your code
} else {
}
}
And then in your 2nd Activity write this
Intent returnIntent = new Intent();
setResult(RESULT_OK, returnIntent);
finish();
Upvotes: 3