如何防止Google地方信息完成我的android活动?

问题描述

我正在尝试在我的应用程序中使用Google Places android lib,它工作得很好。问题是,当用户AutocompleteSupportFragment中选择地点/地址或按返回按钮时,这将完成我的当前活动并返回到主要活动。

我的活动是由于Receiver而打开的活动。

活动调用代码

Intent requestDriverIntent = new Intent(receiverContext,RequestDeliveryActivity.class);
requestDriverIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // required by the app who broadcast
requestDriverIntent.putExtra("line",lineItemId);
requestDriverIntent.putExtra("order",orderId);
receiverContext.startActivity(requestDriverIntent);

这里是我如何使用地方信息回复

private class AddressSelectionListener implements PlaceSelectionListener {
    @Override
    public void onPlaceSelected(@NonNull Place place) {
      deliveryAddress = place.getAddress();
      deliveryLat = place.getLatLng().latitude;
      deliveryLng = place.getLatLng().longitude;
    }

    @Override
    public void onError(@NonNull Status status) {
        errorAlertDialog.show();
    }
  }

解决方法

onBackPressed中覆盖RequestDeliveryActivity方法,不要调用“ super”,而是留空(Activity不会在按下时关闭)或启动另一个{{1} },并致电Activity关闭当前的finish();

Activity
,

在活动中使用重写onBackPressed()方法

尝试:

@Override
public void onBackPressed() {
    finish();
}
,

好的,我发现了错误。我只是从清单中删除了android:noHistory="true"