How to know when activity finished loading?

1.1k views Asked by At

I'm trying to implement ProgressDialog that will load all the activity. So I added this line to the onCreate() method:

pd = ProgressDialog.show(this, "Waiting...", "Please wait five seconds..."); 

but is start loading after all the content was loaded, and its not stop because I don't know where add the line:

pd,dismiss();

So there is any built-in method that called when the activity is show up (like in iOS - viewDidAppear) and another built-in method that called when the activity is finished loading and all the content were loaded?

3

There are 3 answers

0
Shoeb Siddique On

You can dismiss your Dialog in onStop()

@Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
        pd.dismiss();
    }

Or you can dismiss in onDestroy()

@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
      pd.dismiss();
}
0
narancs On

what doest it mean load all the activity ? I think you are on the wrong way. You can`t load all the activities, but you can call an intent what is launch an activity. In this case the activity lifeCycle comes in the picture.

please check out this: http://www.mikestratton.net/assets/android_activity_lifecycle.png

If you would like to us progressdialog, and load any content on the background thread read this: progressDialog in AsyncTask

Good example who to handle dialog in Android: http://examples.javacodegeeks.com/android/core/ui/progressdialog/android-progressdialog-example/ please don`t try to load all of the activities. Never ever call new MyActivity(); NEVER

2
Amsheer On

"The activity I get content from web"

This line i get from your comments which means you are fetching some data in that time you need to show ProgressDialog.

If this is correct then you might be using AsyncTask for the webservice

So you don't need to show dialog from your onCreate method. You need to show your ProgressDialog from AsyncTask onPreExecute() method.

Once it is completed you need to cancel dialog in onPostExecute method

EDIT: AsyncTask Reference http://developer.android.com/reference/android/os/AsyncTask.html This is perfect tutorial.