当数据开始在后台获取时,Android进度微调器加载器停止旋转

时间:2015-02-05 04:18:18

标签: android progressdialog android-volley

我在Async任务的预执行方法上使用进度微调器在UI上显示它,并且数据开始使用volley库从Api在后台获取。问题是当它开始获取数据时,加载器停止旋转并且它就像UI没有响应。

需要帮助,在此先感谢.. ` ProgressDialog对话框;

public void open() {
    dialog = new ProgressDialog(BuzoongaContacts.this);
    dialog.setIndeterminate(true);
    dialog.setCancelable(true);
    dialog.show();
    dialog.setContentView(R.layout.progress_layout);
    dialog.setCanceledOnTouchOutside(false);
}

public void stopLoading() {
    Log.d("res", "stopLoading ");
    try {
        dialog.dismiss();

    } catch (Exception e) {
        // TODO: handle exception
    }
}`

异步任务:

class BuzoongaContactsAsync extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();

        runOnUiThread( new Runnable() {
            public void run() {
                open();
            }
        });


    }

    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        ContactsDataTableOperations conDataTab = new ContactsDataTableOperations(BuzoongaContacts.this);
        conDataTab.open();
        JSONParsingForContactsB.count = 0;
        count = 0;

        if (fromRefresh) 
        {
            if (isInternetConnected()) {
                getBuzzongaContacts();
            } else {
                rl_sub_main_buzoongaContacts.startAnimation(animZoomOut);
                alertDialog("Network Error !",getResources().getString(R.string.network_error));
                rl_alert.startAnimation(animMoveUp);
            }
        } else 
        {
            if (getContactsExistence() == 0) {
                if (isInternetConnected()) {
                    getBuzzongaContacts();
                } else {
                    rl_sub_main_buzoongaContacts.startAnimation(animZoomOut);
                    alertDialog("Network Error !", getResources().getString(R.string.network_error));
                    rl_alert.startAnimation(animMoveUp);
                }
            } else if (Constants.buzoongaContactsAdded) 
            {
                if (isInternetConnected()) {
                    getBuzzongaContacts();
                } else {
                    rl_sub_main_buzoongaContacts.startAnimation(animZoomOut);
                    alertDialog("Network Error !", getResources().getString(R.string.network_error));
                    rl_alert.startAnimation(animMoveUp);
                }
            } else {
                stopLoading();

            }
        }
        arr_list = conDataTab.getAllRecords();
        conDataTab.close();
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);

        cb_select_all.setChecked(false);
        iv_quick_launch.setBackgroundResource(R.drawable.quick_lounch_icon_disable);
        Constants.selected_buzoonga_contacts = 0;
        rl_delete.setAlpha(0.5f);
        rl_delete.setClickable(false);
        rl_show_contacts.setVisibility(View.INVISIBLE);
        mAdapter.notifyDataSetChanged();
    }
}

1 个答案:

答案 0 :(得分:0)

基本上,您无法在后台主题中触摸您的UI元素,这意味着您对startAnimation()stopLoading的所有来电都应该包含runOnUiThread

但我可以看到您的UI代码与您的后台代码密切相关。也许你可以考虑使用Thread&amp; Handler代替AsyncTask