Why is resultCode = -1 here after StartActivityForResult?

Everything works fine, EXCEPT that this action gives resultCode = -1

public class SetTimeDialog extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.settimedialog); Button bUseTime = (Button) findViewById(R.id.buttonUseTime_settime); bUseTime.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent resultIntent = new Intent(this, SetTimeDialog.class); setResult(Activity.RESULT_OK, resultIntent); finish(); } }); 

It is called from here in MainActivity:

  TableLayout timeTable = (TableLayout)findViewById(R.id.timeTable_writepos); timeTable.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { Intent settimedialogIntent = new Intent(getApplicationContext(), SetTimeDialog.class); startActivityForResult(settimedialogIntent, SETTIMEDIALOG_REQCODE); // See onActivityResult() return false; } }); 

And in my onActivityResult method, now I do nothing but check the value of resultCode. (I eliminated all other codes to find out what is wrong).

+6
source share
2 answers

Do you know that RESULT_OK has a value of -1 ?

+16
source

RESULT_OK is -1, and RESULT_CANCELED is 0. Nothing has been done.

+5
source

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


All Articles