Finishactivity doesn't finish the activity?
Asked Answered
F

2

14

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?

Farrah answered 7/12, 2011 at 13:51 Comment(1)
Just put finish() in deleteFile() and let me know what happen..Mendenhall
C
28

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

Centrosymmetric answered 7/12, 2011 at 15:19 Comment(0)
W
6

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

Willianwillie answered 4/12, 2012 at 6:34 Comment(1)
IMO, this answer should've been either a comment or an edition to the accepted answer since it seems to be a valuable contribution. Yet, the poster didn't have enough reputation to comment, and editing an answer is something many people would not dare do (myself included, I prefer suggestions in comments).Dieselelectric

© 2022 - 2024 — McMap. All rights reserved.