[英]Modal Bottom sheet not re-showing when dismiss called
我在我的主要活動中添加了一個模態底部工作表,以便在用戶 GPS/互聯網關閉時顯示。 我添加了一個 LocalBroadcast 接收器,當用戶從手機打開他的 GPS/互聯網時,它可以正常工作。 所以我需要當用戶打開 GPS/internet 來隱藏模態底部表,當他關閉它以始終顯示底部表時。我試過這個只適用於應用程序的初始啟動,也就是說 gps當用戶打開 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();
}
}
};
您可以在 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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.