onActivityResult not being called
Asked Answered
A

1

6

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 ?

Alesha answered 5/7, 2014 at 23:59 Comment(3)
Already checked #7364870 #24493144Alesha
Perhaps try this answer.Vehicle
try to finish then setResultArms
O
7

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.

Overlord answered 6/7, 2014 at 0:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.