我试图关闭我的 Activity 并返回结果,我的父 Activity 中确实有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);
        }
    }

有什么好主意的人为什么它不关门?

最佳答案

finishActivity用于关闭当前的另一个 Activity -http://developer.android.com/reference/android/app/Activity.html#finishActivity(int),因此只需将其更改为finish();

关于android - Finishactivity不能完成 Activity 吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8416384/

10-10 13:48