1

I use startActivityForResult for Activity1 to start Activity2 :

btnSelectFiles.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            savePreferences();
            Intent i = new Intent(getApplicationContext(),
                    FileManagerActivity.class);
            Bundle mBundle = new Bundle();
            mBundle.putString("FileManager", "NewOrder");
            i.putExtras(mBundle);
            startActivityForResult(i, Constants.addFilesCode);

        }
    });

onActivityResult method :

and in Activity2 :

 Intent returnIntent = new Intent();
setResult(1,returnIntent);   
FileManagerActivity.this.finish();

But in the Activity1 requestCode is correct, but the resultCode is always 0.

I do not use Back buttons.

my onActivityResult in the Activity1

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.i(TAG, "onActivityResult");
        Log.i(TAG,
                "onActivityResult requestCode" + Integer.toString(requestCode)
                        + "resultCode" + Integer.toString(resultCode));
        // adding files to the list if the files were added successfully 
        if (requestCode == Constants.addFilesCode)
        {

            // successfull operation
            if (resultCode == 1)
            {
                if (adapter == null)
                    addFiles();
                else if (adapter.getCount() == 0)
                    addFiles();
                else {
                    adapter.notifyDataSetChanged();
                    changeFileHeader();
                }
                btnFilesRemove.setVisibility(View.VISIBLE);
                for (int b = 0; b < FileManagerActivity.getFinalAttachFiles()
                        .size(); b++) {
                    checks.add(b, 0);
                }
            }
        }
Rikki Tikki Tavi
  • 3,089
  • 5
  • 43
  • 81
  • Just checking, but are you checking this value in the `onActivityResult` method of `Activity1`? – kabuko May 21 '14 at 17:33
  • yeah. I recieve requestCode ( is 5 - correct) and resultCode is always 0 – Rikki Tikki Tavi May 21 '14 at 17:36
  • I don't see anything obviously wrong with the code, can you maybe add some more of the surrounding code to help. Where are you calling `setResult` from? Can we see the `onActivityResult` method too? – kabuko May 21 '14 at 17:49
  • Try calling `super.finish();` or just `finish()` in the activity instead `FileManagerActivity.this.finish()`. All seems to be right – Alejandro Alcalde May 21 '14 at 17:51
  • 1
    Please use the constants defined in Activity class. The correct constant in this case is RESULT_OK. Replace 1 by this constant and you correctly get the callback. – nikhil.thakkar May 21 '14 at 18:29
  • Thank you for the comments. But the ways of Activity.RESULT_OK and finish() using doesn't help me. Any else suggestions ? Besides, when I cancel the Activity2, I also get resultCode = 0 in the Activity1. Very weird thing.. – Rikki Tikki Tavi May 22 '14 at 09:39
  • Same problem here. Have you fine the solution? @RikkiTikkiTavi – Dr.jacky Sep 09 '21 at 09:51

1 Answers1

0

My issue was that I was starting activity with FLAG_ACTIVITY_NO_HISTORY. As soon as I removed it, resultCode started propagating back to caller.

Dzmitry Lazerka
  • 1,809
  • 2
  • 21
  • 37