Finishactivity 未完成活动?

发布于 2024-12-19 21:48:46 字数 1356 浏览 1 评论 0原文

我试图让我的活动关闭并返回结果,我的父活动中确实有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苏辞 2024-12-26 21:48:46

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 to finish();

星光不落少年眉 2024-12-26 21:48:46

我将其设置为 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文