简体   繁体   English

从Firebase数据库加载数据时显示进度

[英]Show progress while data loading from Firebase database

I want show progress while data is loaded. 我想在加载数据时显示进度。 It works well. 它运作良好。 But only once. 但是只有一次。 If I press back and again, error occurs. 如果我再按一次,将发生错误。 Searched everywhere, tried everything. 搜索无处不在,尝试了一切。 Please help. 请帮忙。

Working code. 工作代码。

 a.showProgressDialog();

        mUsersDatabaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                        a.hideProgressDialog();
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }

        });

update . 更新 here is error code I got. 这是我得到的错误代码。

Unable to add window -- token android.os.BinderProxy@41ea89e0 is not valid; 无法添加窗口-令牌android.os.BinderProxy@41ea89e0无效; is your activity running? 您的活动正在进行吗?

Tried. 试过了 Count pairs show -- dissmiss. 计数对显示-开除。 Equal. 等于。 Not helped. 没有帮助。 Tried. 试过了 Make showProgress not static. 使showProgress不是静态的。 Not helped. 没有帮助。 ll try put dissmiss on ui thread? 会尝试将dissmiss放在ui线程上吗? Should help. 应该有帮助。 Update later. 稍后更新。

showProgressDialog method was like this. showProgressDialog方法就是这样。

  public void showProgressDialog() {
    if (mProgressDialog == null) {
        mProgressDialog = new ProgressDialog(a);
        mProgressDialog.setMessage("Loading...");
        mProgressDialog.setIndeterminate(true);
    }

    if (!a.isFinishing()) {
        mProgressDialog.show();
    }

}

After testing and going deep into it I found the problem. 经过测试并深入研究后,我发现了问题所在。 As it was in preference activity and fragments was static, this method added was also static. 由于它是首选活动,并且片段是静态的,因此添加的此方法也是静态的。 Later I decided this might be bad, and moved it to not static. 后来我认为这可能不好,然后将其移至非静态。

It does not helped at a glance, but after a break I looked again and found that mProgressDialog variable was still static. 乍一看并没有帮助,但是休息片刻后,我再次看了看,发现mProgressDialog变量仍然是静态的。 Changed it to none-static and that solved my crash. 将其更改为非静态,这解决了我的崩溃问题。

Thanks all for help. 谢谢大家的帮助。

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

相关问题 从firebase数据库获取数据时显示“进度”对话框 - Show Progress dialog while fetching data from firebase database 从 Firebase 数据库获取数据时如何显示加载消息? - How to show loading message while fetching data from Firebase Database? 加载Firebase数据库时显示进度条 - Showing progress bar while loading Firebase database 从数据库加载数据时添加进度条 - Add Progress bar while data loading from database 从firebase数据库获取数据时显示进度对话框 - Showing progress dialog while getting data from firebase database 加载数据时显示进度对话框 - show progress dialog while loading data 在加载数据时以片段形式显示不确定的进度+加载消息 - Show an indeterminate progress + loading message in fragment while data is loading 从Firebase实时数据库加载数据时,如何添加进度栏? - How to add a progress bar when data is loading from Firebase real-time database? 我想显示进度对话框,直到从 Firebase 数据库收到数据 - I want to show the Progress Dialog until the data is received from the Firebase Database 在将数据加载到SQLite数据库时显示进度指示器的策略? - Strategy for displaying a progress indicator while loading data into an SQLite database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM