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

Tom*_*ola 7 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();
        }
    });
Run Code Online (Sandbox Code Playgroud)

它在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;
        }
    });
Run Code Online (Sandbox Code Playgroud)

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

War*_*ith 19

你知道RESULT_OK有价值-1吗?

  • 是的,我的反思只是将常数的值-1视为出错的标志.晚安! (2认同)

Ses*_*nay 5

RESULT_OK是-1,RESULT_CANCELED是0.没有错.