[英]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.