Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is resultCode = -1 here after StartActivityForResult?

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).

like image 390
Tombola Avatar asked Feb 21 '12 12:02

Tombola


People also ask

What is the replacement of startActivityForResult?

0 . It has deprecated startActivityForResult in favour of registerForActivityResult . It was one of the first fundamentals that any Android developer has learned, and the backbone of Android's way of communicating between two components.

Can startActivityForResult still be used?

From now, startActivityForResult() has been deprecated so use new method instead of that. Save this answer. Show activity on this post. There are 4 simple steps to follow while replacing the deprecated method startActivityForResult(...) .

Is startActivityForResult deprecated?

It has deprecated startActivityForResult in favour of registerForActivityResult . It was one of the first fundamentals that any Android developer has learned, and the backbone of Android's way of communicating between two components.

What is purpose of startActivityForResult () function?

By the help of android startActivityForResult() method, we can send information from one activity to another and vice-versa. The android startActivityForResult method, requires a result from the second activity (activity to be invoked).


1 Answers

You know that RESULT_OK has the value -1?

like image 64
WarrenFaith Avatar answered Oct 10 '22 16:10

WarrenFaith