0

I'm new to asking questions here so any advice about that will be appreciated...but to my problem:enter code here

I am Trying To show Process Dialague While Waiting for Data From Server..I am Using Retrofit Call For Get Data From Server And Using MVP Pattern In Our Project.. But Showing Black Screen While Call Goes To Server.. And Load Content Directly After Gettting Response I Am Stuck This Point From Few Days..

   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();

    }`

Thanks for any help

  • Although built in `onCreate`, the screen is not actually displayed there. `onCreate` queues up actions to complete later. You need to let `onCreate` finish as soon as possible. Move any longer-running processing to another lifecycle callback such as `onResume` and don't hang up in `onCreate`. Not sure if this is your issue, but I hope it helps. – Cheticamp Mar 01 '17 at 12:48

1 Answers1

0

You are doing too much work in the OnCreate main Thread. This is why it freezes your Android Application.

Do your Progress UI in the Main thread like so:

 @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();

}

This might help you: ProgressDialog in a separate thread

Community
  • 1
  • 1
Johnathan Logan
  • 357
  • 5
  • 14