如何防止 Google 地方完成我的 android activity?

How to prevent Google Places finish my android activity?

我正在尝试在我的应用程序中使用 Google Places android 库,它运行良好。问题是,当用户 select AutocompleteSupportFragment 中的 place/address 或按下后退按钮时,这完成了我当前的 activity 和 returns 到主 activity.

我的 activity 是 activity,它是 Receiver 的结果。

activity调用代码

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);

下面是我如何使用 Places 响应

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

覆盖 RequestDeliveryActivity 中的 onBackPressed 方法,不要调用 'super',而是留空(Activity 不会在返回时关闭)或启动另一个Activity 如果需要并调用 finish(); 关闭当前 Activity

@Override
public void onBackPressed() {
    // leave empty or start smth new
}

在 activity

中使用覆盖 onBackPressed() 方法

试试这个:

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

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