¿Cómo ir a la actividad anterior con setResult?

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.

preguntado el 31 de julio de 12 a las 13:07

what does it mean as it is going some time and then after it is not going - means activity is not finishing ?? You debugged ?? finish() is getting called all the time ?? -

prueba este aquí Prueba esta tutoriales for deep explaination Hope it helps nJoy!! -

In my code finish is mentioned, this block of code is running every time. what can be issue in this. should i post onActivityForResult method of parent activity. -

clear your stack activity using addflag on Intent, might help. Like this mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); -

Wow , thax Mitesh Agarwal , its works for me. Thanx for saving my day. :) -

2 Respuestas

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();

Respondido 31 Jul 12, 13:07

gaurav is saying activity itself is not getting finished, is your cade is helpful for the same ?? - daud arfin

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);

Respondido 31 Jul 12, 13:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.