OnActivityResult not called

The first activity (EditCycle) calls the second action (EditChooseLists)

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

The second action (EditChooseLists) ends 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(); 

1st activity (EditCycle) has an onActivityResult method, 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); } 

But nothing happens when the 2nd activity resumes, nothing in the console, no toasts, the text does not change

I concluded that onActivityResult is then not called

Can anyone help?

+6
source share
1 answer

Your problem is here:

 startActivityForResult(i, RESULT_OK); 

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

void startActivityForResult (Intent intent, int requestCode)

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

+7
source

Source: https://habr.com/ru/post/971811/


All Articles