7

Everything works fine, EXCEPT that this activity 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 I now do nothing but check the value of resultCode. (I've eliminated all other code to find out what's wrong).

Tombola
  • 1,131
  • 5
  • 15
  • 26

2 Answers2

23

You know that RESULT_OK has the value -1?

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
  • 2
    Yes, It was just a reflex of mine to consider the value -1 of a constant to be a sign of something being wrong. Good night! – Tombola Feb 21 '12 at 12:57
  • You know, it's funny, I had the exact same reaction when I saw -1 being returned. I think it has to do with my Flex / AS3 background as that's typically the value of certain things like the length of result sets etc... when they are 'empty' – Justin Buser May 30 '12 at 13:16
5

RESULT_OK is -1, and RESULT_CANCELED is 0. Nothing is wrong.

Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109