This is an Android startActivityForResult question.

Asked 2 years ago, Updated 2 years ago, 20 views

I sent it from an activity called A to an activity called B from Android to startActivityForResult.

When B-Activity ended the screen, I set the result value as setResult and sent it to you

A activity has only zero result value

The actual value sent should be only one of the two 1000/1001 values.

The content value is also null, but there is no strange log on the log.

I have no idea what the problem is.

If you have this kind of experience, please help me.

Blockquote Start activity sending part

    Intent cIntent = new Intent(Activity_searchs.this, Activity_Search_Result.class);
    cIntent.putExtra("SearchWord", s);
    cIntent.putExtra("is_store", isStore);
    startActivityForResult(cIntent, 7777);

Blockquote SetResult part

    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (LMain.refreshFlag) {
                        setResult(nResult);
                    }
                    finish();
        }
    });

OnActivityResult part

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.e("SJW", "RequestCode > "+requestCode+" / resultCode > "+resultCode);
        if(requestCode == 7777){
            if(resultCode == 1001){
                finish();
            }
        }
    }

It looks like this.

In the onActivityResult part, the resultCode always enters only 0.<

android

2022-09-21 16:32

1 Answers

The first parameter of setResult is a value to pass values such as RESULT_CANCELED or RESULT_OK. If you want to deliver the result as a value, setResult as below.

Intent returnIntent = new Intent();
returnIntent.putExtra("result",1000);
setResult(RESULT_OK,returnIntent);
finish();

Read data.getIntExtra("result",0); on the side where you read the value. 0 is the default value if the value cannot be read.

Could you correct the question and upload the code for the SetResult and the onActivityResult? If you see the result value as 0, it seems that the default value is entered in getIntExtra.


2022-09-21 16:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.