Finishactivity 未完成活动?
我试图让我的活动关闭并返回结果,我的父活动中确实有 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);
}
}
任何人有任何好主意为什么它不关闭吗?
I'm trying to get my activity to close and return with the result, I do have onActivityResult in my parent activity, and I have used close to the same method below in other places where it works.
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");
}
}
This method was called from this menu :
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);
}
}
Anyone with any bright ideas why it doesnt close?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
finishActivity
用于关闭当前的另一个 Activity - http ://developer.android.com/reference/android/app/Activity.html#finishActivity(int),所以只需将其更改为finish();
finishActivity
is used to close another activity from current - http://developer.android.com/reference/android/app/Activity.html#finishActivity(int), so just change it tofinish();
我将其设置为 finish(),即使有返回,但它不会关闭,然后我意识到该特定 Activity 需要清单中的
android:launchMode="singleTask"
I had it as finish() even with a return but it wouldn't close, then I realized that that particular Activity needed the
android:launchMode="singleTask"
in the Manifest