Skip to content Skip to sidebar Skip to footer

How To Display A Loading Screen While Doing Heavy Computing In Android?

I am working on a program that searches the users phone for some date, which takes about 2-3 seconds. While it's computing I want to display a loading screen, so the user knows som

Solution 1:

Try to handle it in this way

mProgressDialog = ProgressDialog.show(this, "Please wait","Long operation starts...", true);
        newThread() {
            @Overridepublicvoidrun() {

               //Do long operation stuff here search stufftry {

                    // code runs in a threadrunOnUiThread(newRunnable() {
                        @Overridepublicvoidrun() {
                            mProgressDialog.dismiss();
                        }
                    });
                } catch (final Exception ex) {

                }
            }
        }.start();

Solution 2:

Use async task for heavy task. Put your progress dialog code in onPreExecute method progress dialog dismiss code in onPostExecute method and all your heavy task in doInBackground method.

Solution 3:

try passing down the context on a new class with your progress bar (this goes on your main activity)

NAME_OF_YOUR_CLASScontext=newNAME_OF_YOUR_CLASS(getApplicationContext());

and on your class call the method like this..(this goes on class)

publicNetworking(Context c){
        this.context= c;
    }

dont forget to make context a field (private final Context context;)

hope this helps

also idk if this will work but try to extend AsyncTask and use methods to run your progress bar there.

Post a Comment for "How To Display A Loading Screen While Doing Heavy Computing In Android?"