【问题标题】:onActivityResult is not calling between activitesonActivityResult 没有在活动之间调用
【发布时间】:2017-12-10 07:07:05
【问题描述】:

在这里,我尝试将一些值传递给第二个活动(孩子)到第一个活动(父母)。我注意到在 API-21 中调用了设备 onActivityResult 的以上版本,但对于 API-19 及以下版本,它没有被调用。这里分享我的sn-ps代码,请查收。

感谢您的回答!!!

在父活动中:

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

在子活动中

   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" />

【问题讨论】:

  • 您的清单看起来如何?
  • 请检查清单代码@MuratK。
  • 移除 android:launchMode="singleTask".

标签: android onactivityresult android-api-levels


【解决方案1】:

1:从我遇到问题的活动中删除 android:noHistory="true" 为我解决了问题

2:如果您有android:launchMode=“singleTask”,请更改为android:launchMode=“standard”

希望对你有帮助!!!!

【讨论】:

  • 通过将 android:launchMode=“singleTask” 更改为 android:launchMode=“standard”。它是有效的。谢谢@Adnan Maqbool
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-02
  • 1970-01-01
  • 1970-01-01
  • 2019-03-31
  • 2014-08-26
相关资源
最近更新 更多