0

我在我的主要活动中添加了一个模式底部表,以便在用户 GPS/互联网关闭时显示。我添加了一个 LocalBroadcast 接收器,以便在用户从手机打开他的 GPS/互联网时进行收听,这可以正常工作。所以我需要当用户打开 GPS/internet 以隐藏模态底部表时,当他将其关闭以始终显示底部表时。我已经尝试过 这个,它只在应用程序的初始启动时有效,即当我们说 gps is off the bottom sheet dialog 当用户打开 gps 时显示它消失但问题是在它第一次关闭后当用户现在关闭 gps 时它没有按预期显示并且广播接收器被触发。这是我的广播接收器

 private BroadcastReceiver locationSwitchStateReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {

            if (android.location.LocationManager.PROVIDERS_CHANGED_ACTION.equals(intent.getAction())) {

             validateGPSAndInternet();

            }
        }
    };
4

1 回答 1

0

您可以在 ConnectionBottomSheet 中声明静态变量以关闭片段外的底部工作表。

public class ConnectionBottomSheet extends BottomSheetDialogFragment {  

    public static ConnectionBottomSheet fragment;     
    //your code

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            CON_TYPE = getArguments().getString(con_type);

        }
     fragment=this;
   }
   @Override
   public void onDestroy() {
        super.onDestroy()
       fragment=null;
    }
  //your code 
}

调用主要活动

 if(ConnectionBottomSheet.fragment!=null && ConnectionBottomSheet.fragment.getDialog()!=null)
    ConnectionBottomSheet.fragment.getDialog().dismiss()
于 2020-03-04T07:06:32.593 回答