简体   繁体   中英

Modal Bottom sheet not re-showing when dismiss called

I have added a modal bottom sheet in my main activity to be displayed whenever the user GPS/internet is off. I have added a LocalBroadcast receiver to listen when the user switch on his GPS/internet from the phone which works fine. So I need when the user switch GPS/internet on to hide the modal bottom sheet and when he switch it off to always shows the bottom sheet.I have tried this which only works at the intial launch of the application that is when let say gps is off the bottom sheet dialog is shown when the user turn on the gps it disappear but problem is after it dismissed for first time when user now turn off the gps its is not getting displayed as expected and broadcast receiver is getting triggered. And here is my broadcast receiver

 private BroadcastReceiver locationSwitchStateReceiver = new BroadcastReceiver() {

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

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

             validateGPSAndInternet();

            }
        }
    };

you can declare the static variable in ConnectionBottomSheet for close the bottom sheet on out of fragment.

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 
}

call in main activity

 if(ConnectionBottomSheet.fragment!=null && ConnectionBottomSheet.fragment.getDialog()!=null)
    ConnectionBottomSheet.fragment.getDialog().dismiss()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM