简体   繁体   English

调用解雇时不重新显示模态底部工作表

[英]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.我在我的主要活动中添加了一个模态底部工作表,以便在用户 GPS/互联网关闭时显示。 I have added a LocalBroadcast receiver to listen when the user switch on his GPS/internet from the phone which works fine.我添加了一个 LocalBroadcast 接收器,当用户从手机打开他的 GPS/互联网时,它可以正常工作。 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.所以我需要当用户打开 GPS/internet 来隐藏模态底部表,当他关闭它以始终显示底部表时。我试过这个只适用于应用程序的初始启动,也就是说 gps当用户打开 gps 时,会显示底部表单对话框消失,但问题是当用户现在关闭 gps 时它第一次关闭后,它没有按预期显示并且广播接收器被触发。 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.您可以在 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 
}

call in main activity调用主要活动

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解雇后重新显示对话框 - Re-showing dialog after dissmiss 第二次调用时,Bottom Sheet Fragment会导致错误 - Bottom Sheet Fragment causes error when called the second time 当ProgressDialog dismiss方法被称为android时发生NullPointerException - NullPointerException when ProgressDialog dismiss method is called android 如何使用 kotlin 在 recyclerview 中执行模态底部工作表对话框 - How to do modal bottom sheet dialog in recyclerview with kotlin 隐藏/显示底部工作表内的片段会将底部工作表的状态设置为展开 - Hiding/showing a fragment that's inside a bottom-sheet sets the bottom-sheet's state to expanded 底部工作表展开时使用 animation 最小化底部导航栏 - Minimize bottom navigation bar with animation when bottom sheet is expanded .dismiss()在AlertDialog中显示错误 - .dismiss() is showing an error in AlertDialog 我正在尝试创建顶部带有线条的自定义模态底部表,我该如何实现? - I am trying to create custom modal bottom sheet with line on the top, how can I achieve that? 当兄弟滚动到达结尾时打开底部? - Open bottom sheet when sibling scrolling reaches the end? Android:如何在片段中按返回按钮时隐藏底页? - Android: How to hide bottom sheet when back button is pressed in fragment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM