我正在尝试让我的活动关闭并返回结果,我在父活动中确实有onActivityResult,并且我在其他有效的地方使用了接近相同的方法。
public void deleteFile(){
boolean deleted=FileManager.getInstance().deleteMeasurementData(this.getIntent().getData(), this);
if(deleted){
Toast.makeText(this, originalData.getName() +".mmd Has been deleted", Toast.LENGTH_SHORT);
setResult(EditMeasurement.RESULT_YES_DELETED);
finishActivity(EditMeasurement.RESULT_YES_DELETED);
}else {
Toast.makeText(this, originalData.getName() +".mmd did NOT delete", Toast.LENGTH_SHORT);
Log.e(TAG, "File did NOT delete error");
}
}
从此菜单调用此方法:
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
Log.i(TAG, "something choosen "+item.getItemId()+" it should have been: "+R.id.om_measurement_menu_delete);
switch (item.getItemId()) {
case R.id.om_measurement_menu_edit:
editFile();
return true;
case R.id.om_measurement_menu_delete:
deleteFile();
return true;
case R.id.om_measurement_menu_cancel:
endActivity();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
任何有明智想法的人为什么不关闭?
答案 0 :(得分:27)
finishActivity
用于关闭当前的另一项活动 - http://developer.android.com/reference/android/app/Activity.html#finishActivity(int),因此只需将其更改为finish();
答案 1 :(得分:6)
我把它作为finish()即使返回但它也不会关闭,然后我意识到那个特定的Activity需要在Manifest中android:launchMode="singleTask"