尝试将 setResult 返回父活动时发生了一些奇怪的事情,onActivityResult 方法未执行并且我的应用程序在此处终止是父活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("MyAPP","Access Calendar");
//Getting the token back from authorization process
accessToken = getIntent().getExtras().getString("token");
// Setting up Calendar API Service
setupCalendarConnection();
startActivityForResult(intent.setClass(this, CalendarTasks.class),REQUEST_CAL_TASK);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("MyAPP", "result arrived");
if(requestCode==REQUEST_CAL_TASK){
switch (resultCode){
case CREATE_EVENT:
getUserCalendars();
break;
case QUICKADD_EVENT:
getUserCalendars();
startActivityForResult(intent.setClass(this, CalendarQuickAddActivity.class),REQUEST_CAL_ACT);
break;
case VIEW_EVENTS:
getUserCalendars();
break;
case CREATE_CALENDAR:
getUserCalendars();
break;
case EDIT_CALENDAR:
getUserCalendars();
break;
}
}
super.onActivityResult(requestCode, resultCode, data);
}
这是儿童活动
listView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
listIndex=position;
Log.d("MyAPP", ""+position);
switch (listIndex){
case 0:
Log.d("MyAPP","case 0"+listIndex);
setResult(CREATE_EVENT);
finish();
break;
case 1:{
Log.d("MyAPP","case 1"+listIndex);
setResult(QUICKADD_EVENT);
finish();
break;
}
case 2:
Log.d("MyAPP","case 2"+listIndex);
setResult(VIEW_EVENTS);
finish();
break;
case 3:
Log.d("MyAPP","case 3"+listIndex);
setResult(CREATE_CALENDAR);
finish();
break;
case 4:
Log.d("MyAPP","case 4"+listIndex);
setResult(EDIT_CALENDAR);
finish();
break;
}
}
});
我正在检查案例 1,Log cat 打印出正确的日志,但在 onActivityResut 方法中没有打印该日志,这意味着它不会返回,我不知道这背后的原因。我移动了 switch 块来覆盖 finish() 方法,我遇到了同样的问题。