0

I had given my web application url in Main Activity.java file of Android project to convert into Android application using Phone Gap framework. My application is taking time to load in Android device, hence I want to give loading image while loading.

I had given code like this:

       super.setIntegerProperty("loadUrlTimeoutValue", 100000);     
       super.loadUrl("http://abc company/application"); 

       ProgressDialog progressDialog = new ProgressDialog(this);
       progressDialog.setMessage("Loading...");
       progressDialog.setCancelable(true);
       progressDialog.setIndeterminate(true);          
       progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
       progressDialog.setProgress(0); // set percentage completed to 0%      
       progressDialog.show();          
      //  progressDialog.dismiss(); 

But progress dialog is showing after load of my application, but I want to dismiss it after loading. Is there any need of if condition here?

1 Answer 1

1

You have to create the Dialog on the UI thread and show it and then fire the load of the application in other Thread who should dismiss the dialog when the thread work has finished.

Here you have an example:

Android tutorial: How to make a progress dialog

Code sample:

private void runDialog(final int seconds)
{
        progressDialog = ProgressDialog.show(this, "Please wait....", "Here your message");

        new Thread(new Runnable(){
            public void run(){
                try {
                                  //Do your application load here

                    progressDialog.dismiss();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.