Reputation: 1
I have a problem with my Android app coding as follows:
I use dismiss()
to hide a dialog, but dialog just does not disappear as expected. Dialog remains in activity interface while dismiss() is actually called.
It feels like get stucked or something else. Hardware back button does not work either. App just gets stuck in there. Can anyone help me out Thanks in advance.
Example pic
And there are some related code. I use MVP architect.
@Override
public void editAllNum(Context context, int num, List<ShopCar.GoodListBean> goodList) {
Subscription s = Observable.just(num)
.filter(integer -> goodList.size() != 0) //the goodList of size is never equal to 0.
.subscribeOn(Schedulers.io())
.compose(TransformerUtil.showLoadingDialog(mView)) //call show dialog.
.flatMap(new Func1<Integer, Observable<List<ShopCar.GoodListBean>>>() {
@Override
public Observable<List<ShopCar.GoodListBean>> call(Integer num) {
List<ShopCar.GoodListBean> list = new ArrayList<ShopCar.GoodListBean>();
for ( ShopCar.GoodListBean item : goodList ) {
if ( item.getRemainNum() != 0 ) {
if ( item.getRemainNum() > num ) {
if ( item.getLimit() != 0 ) {
item = editNum(item, num); //editNum is not important
} else {
item.setNum(num);
}
} else {
if ( item.getLimit() != 0 ) {
item = editNum(item, num);
} else {
item.setNum(item.getRemainNum());
}
}
}
list.add(item);
}
return Observable.just(list);
}
})
.flatMap(new Func1<List<ShopCar.GoodListBean>, Observable<List<ShopCar.GoodListBean>>>() {
@Override
public Observable<List<ShopCar.GoodListBean>> call(List<ShopCar.GoodListBean> temp) {
return mPaymentImpl.updateGoodsNumAndQuery(context, temp); //operate databases update some data.
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<List<ShopCar.GoodListBean>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
mView.dismissLoadingDialog();
}
@Override
public void onNext(List<ShopCar.GoodListBean> list) {
mView.dismissLoadingDialog();// call dismiss dialog.
mView.setShopCarFromDB(list);
}
});
addSubscription(s);
}
@Override
public void showLoadingDialog() {
if ( mLoadingDialog == null ) {
mLoadingDialog = new LoadingDialog(getContext());
LogUtils.e(" show loading dialog = " + mLoadingDialog);
}
mLoadingDialog.show();
}
@Override
public void dismissLoadingDialog() {
if ( mLoadingDialog != null ) {
LogUtils.e(" dismiss loading dialog ");
mLoadingDialog.dismiss();
}
}
some code of Dialog.
public class LoadingDialog extends Dialog {
public LoadingDialog(Context context) {
super(context, android.R.style.Theme_Translucent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.widget_loading_dialog);
setCanceledOnTouchOutside(true);
setCancelable(true);
}
}
//XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/loading_dialog_bg"
>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>
</RelativeLayout>
Finally, sorry my English.
Upvotes: 0
Views: 113
Reputation: 742
Check if the value of mLoadingDialog is null first. Maybe somehow the value is null. ie. the dialog u see on the screen might not be that mLoadingDialog. By change the function below, what did you see in logcat?
@Override
public void dismissLoadingDialog() {
if ( mLoadingDialog != null ) {
LogUtils.e(" dismiss loading dialog ");
mLoadingDialog.dismiss();
}else{
LogUtils.e("mLoadingDialog is null skip dismiss loading dialog ");
}
}
Upvotes: 1