onActivityResult 不是在活动之间调用

onActivityResult is not calling between activites

这里我尝试将一些值传递给第二个 activity(Child) 到第一个 activity(Parent)。我注意到在 API-21 以上版本的设备 onActivityResult 中被调用,但对于 API-19 及以下版本,它没有被调用。在这里,我分享了我的 code.Please 检查它的片段。

非常感谢您的回答!!!

在parent activity:

第 1 步

Intent intent = new Intent(ABCAct.this, DEF.class);
                intent.putExtra("mapPickDrop", "1");
                intent.putExtra("location_lat", P_latitude);
                intent.putExtra("location_lng", P_longitude);
                intent.putExtra("address", pickupAddressFlag);
                startActivityForResult(intent, 2018);

第 2 步:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

  if (requestCode == 2018) {
            if (resultCode == RESULT_OK) {
                Double lat = data.getDoubleExtra("location_lat", 0.0);
                Double lng = data.getDoubleExtra("location_lng", 0.0);
                String add = data.getStringExtra("location_address");
                String mapPickDrop = data.getStringExtra("mapPickDrop");

                if (mapPickDrop.equals("1")) {
                    P_latitude = lat;
                    P_longitude = lng;
                    pickupAddressFlag = add;
                    TaxiUtil.bookTaxiPickUpDrop = 1;
                    if (P_latitude != 0.0 && P_longitude != 0.0 && D_latitude == 0.0 && D_longitude == 0.0) {
                        setLocation(P_latitude, P_longitude, "");
                    }
                }
                if (mapPickDrop.equals("2")) {
                    TaxiUtil.bookTaxiPickUpDrop = 2;
                    D_latitude = lat;
                    D_longitude = lng;
                    DroplocEdt.setText("" + add); 
                    showPickupDropMarkers();
                }
            }
        }
    }

在Childactivity

   Intent back = new Intent();
            back.putExtra("location_lat", P_latitude_new);
            back.putExtra("location_lng", P_longitude_new);
            back.putExtra("location_address",         PicklocEdt_1.getText().toString());

            back.putExtra("mapPickDrop", mapPickDrop);
            setResult(RESULT_OK, back);
            finish();

清单

<activity
            android:name=".ABCAct"
            android:configChanges="orientation|keyboardHidden"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden|stateAlwaysHidden">

     <activity
            android:name=".DEF"
            android:configChanges="orientation|keyboardHidden"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden|stateAlwaysHidden" />

1:从 activity 中删除 android:noHistory="true" 我遇到了问题并为我解决了这个问题

2:如果你有 android:launchMode=“singleTask” 更改为 android:launchMode=“standard”

希望对您有所帮助!!!