除了使用startActivityForResult和setResult之外,resultCode为0

时间:2014-05-21 17:31:45

标签: android android-intent android-activity onactivityresult

我使用startActivityForResult for Activity1来启动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方法:

并在Activity2中:

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

但是在Activity1中 requestCode是正确的,但resultCode始终为0.

我不使用后退按钮。

我在Activity1中的onActivityResult

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

1 个答案:

答案 0 :(得分:0)

我的问题是我正在使用FLAG_ACTIVITY_NO_HISTORY开始活动。我删除它后,resultCode开始传播回来电。