0

我是在这里提问的新手,所以任何关于此的建议都将不胜感激......但我的问题是:enter code here

我试图在等待来自服务器的数据时显示进程对话..我正在使用改造调用从服务器获取数据并在我们的项目中使用 MVP 模式..但是在调用转到服务器时显示黑屏..并在之后直接加载内容得到回应我从几天开始就被困在这一点上。

   public class ReceiptRegisterActivity extends AppCompatActivity   implements ReceiptRegisterPresenter.ReceiptRegisterPresenterListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
     setContentView(R.layout.activity_receipt_register);
        progressBar = new ProgressDialog(ReceiptRegisterActivity.this);

        progressBar.setCancelable(true);
        progressBar.setMessage("Fetching Data...");
        progressBar.setProgress(20);
        progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressBar.show();
        progressBarStatus = 0;
spinner = (SearchableSpinner)findViewById(R.id.spinner);
        editsearch = (android.widget.SearchView) findViewById(R.id.search);
        editsearch.setOnQueryTextListener(this);
        expandButton =(Button)findViewById(R.id.expandButton);
        byDate =(Button)findViewById(R.id.byDate);
        byCustomer=(Button)findViewById(R.id.byCustomer);
        byDate.setFocusable(false);
        allEventLIstener();
dbHelperObj=new DBHelper(this);
        try{
            dbHelperObj.createDB();
        }catch (Exception e){
            throw new  Error(e);
        }
        try{
            dbHelperObj.openDataBase();

        }catch (SQLiteException e){
            e.printStackTrace();
        }
        //srActivity = this;
        // progressBar = new ProgressBar(this);
        //   progressBar.setVisibility(View.VISIBLE);

       receptRegisterPresenterObj =  new ReceiptRegisterPresenter(this,this);
        receptRegisterPresenterObj.getReceiptRegisterData();
}
 public void receiptRegisterDataReady(Object obj) {


       /// Getting Response In This Block Doing Some Manupilation And Dismiss progressBar...      
        progressBar.dismiss();

    }`

谢谢你的帮助

4

1 回答 1

0

您在 OnCreate 主线程中做了太多工作。这就是它冻结您的 Android 应用程序的原因。

在主线程中执行进度 UI,如下所示:

 @Override
protected void onCreate(Bundle savedInstanceState) {
     setContentView(R.layout.activity_receipt_register);

   progressBar = new ProgressDialog(this, "title", "loading");

    heavywork();

}

   public void heavywork()
{

//start a new thread to process job
     new Thread(new Runnable() {  
         @Override  
         public void run() { 
             // Do all the Data From Server code here ! 
          }  
      }).start();

}

这可能会对您有所帮助: ProgressDialog in a separate thread

于 2017-03-03T08:19:36.407 回答