这里我试图将一些值传递给第二个活动(Child)到第一个活动(Parent)。我已经注意到在API-21上面调用了设备版本onActivityResult但是对于API-19及其下面的版本,它不会被调用。在这里,我分享我的代码片段。请检查它。
您的回答更受赞赏!!!
在父级活动中:
第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" />
答案 0 :(得分:1)
1:从我遇到问题的活动中删除android:noHistory="true"
解决了我的问题
2:如果您有android:launchMode=“singleTask”
到android:launchMode=“standard”
希望它有所帮助!!!!