为什么在StartActivityForResult之后resultCode = -1?

时间:2012-02-21 12:23:18

标签: android android-intent

一切正常,除了此活动给出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();
        }
    });

从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;
        }
    });

在我的onActivityResult方法中,我现在什么都不做,只检查resultCode的值。 (我已经删除了所有其他代码以找出问题所在。)

2 个答案:

答案 0 :(得分:18)

您知道RESULT_OK的值为-1

答案 1 :(得分:5)

RESULT_OK为-1,RESULT_CANCELED为0.没有错。