Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onActivityResult not being called

The 1st Activity (EditCycle) calls the 2nd activity (EditChooseLists)

Intent i=new Intent(EditCycle.this,EditChooseLists.class);
startActivityForResult(i, RESULT_OK);

The 2nd activity (EditChooseLists) is ended as such

Toast.makeText(EditChooseLists.this, list.get(position), Toast.LENGTH_SHORT).show();            
Intent i=new Intent();
i.putExtra("desc",content);
i.putExtra("content", list.get(position));
setResult(RESULT_OK,i);
finish();

The 1st Activity (EditCycle) has the method onActivityResult overridden as such

@Override
public void onActivityResult(int requestCode,int resultCode,Intent data){
    super.onActivityResult(requestCode, resultCode, data);
    System.out.print("Test Result !");

    String content=data.getExtras().getString("content");
    System.out.println("result String"+content);
    Toast.makeText(EditCycle.this,content, Toast.LENGTH_SHORT).show();
    TextView t=(TextView)findViewById(R.id.tv_editcycle_cropLbl);
    t.setText(content);
}

Yet nothing happens when the 2nd activity is resumed, nothing in the console, no toast, textview unchanged

I've concluded that the onActivityResult then is not being called

Can anyone help ?

like image 616
steff_bdh Avatar asked Jul 05 '14 23:07

steff_bdh


1 Answers

Your problem is here:

startActivityForResult(i, RESULT_OK);

Because RESULT_OK == -1 and passing a negative value as the second parameter to startActivityForResult breaks this promise in the method itself (from the Android Developer documentation):

void startActivityForResult (Intent intent, int requestCode)

requestCode int: If >= 0, this code will be returned in onActivityResult() when the activity exits.

like image 156
bwegs Avatar answered Sep 20 '22 17:09

bwegs