一切正常,除了此活动给出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的值。 (我已经删除了所有其他代码以找出问题所在。)
答案 0 :(得分:18)
您知道RESULT_OK
的值为-1
?
答案 1 :(得分:5)
RESULT_OK
为-1,RESULT_CANCELED
为0.没有错。