views:

109

answers:

2

HI, Im trying to show a ProgressDialog while the activity is loading. my problem is that although i completed all the work in the activity it takes a long time for the activity to load, i suspect this is because i use multiple views with multiple listviews with custom array adapters inside a viewflipper. it takes a long time for the UI to show.

how would i go about checking that all the UI inside the activity finished loading?

or is there a way to preload all the activity and the UI?

Thanks,

A: 

Use Asynctask

  new DownloadTask().execute();


  private class DownloadTask extends AsyncTask<String, Void, Object> {

    protected void doInBackgroind(Void... arg0){
    //Do time Consuming Processing
    publishProgres()
    return null;
    }

    protected void onProgressUpdate(Void... arg0){
    }

    protected void onPostExecute(Void... result){
    log.i("AvtivityInfo", "activity finished loading...");
    }

}    
Jorgesys
Not sure if that will work... I'll have to give it a try by my own.
Cristian
How exactly will this help? my problem is that the UI isnt showing up even though the activity already recived all the visible inication messages such as "public void onWindowFocusChanged (boolean hasFocus)"all the UI stuff is the on create, i suspect the listview adapters are doing something in the backgroud and thats the main issue
totem
The problem is its not a "task" there is no download or communication or any async operation involved here its only loading the resources from XML and it all happens in the OnCreate which takes less than a second to complete, however the UI is only truly visible after 8 seconds or so.
totem
try this sample to understand http://stackoverflow.com/questions/1979524/android-splashscreen, display a progressDialog in the UI till the data is completely loaded. if you see the UI after 8 seconds that means there´s a process blocking your UI, maybe your ArrayAdapter loading.
Jorgesys
I agree that the ArrayAdapter loading is whats making the UI not visible, my question is how can i check that tis finished loading?
totem
protected void onPostExecute(Void... result){ log.i("AvtivityInfo", "activity finished loading..."); }
Jorgesys
A: 

If you think you need a ProgressDialog because your activity is opening too slowly, you have much bigger problems. Android is likely to kill off your activity with an activity-not-responding error.

You can either get sophisticated and use Traceview to find your performance issue, or you can just experiment. For example, you can skip setting adapters in your ListViews, to confirm that the problem indeed lies there.

Jorgesys had the right answer in his now-deleted entry, from what I can tell. I suspect that loading your adapters is taking the time, perhaps in database queries, and you need to move some of that into AsyncTasks.

CommonsWare
Thats the thing there are no DB queries, nothing but work with drawables and layouts. i cant think of what to break up into AsyncTasks because all the work is in the OnCreate which is very fast. Is the ArrayAdapter loading async? and if so is there a way to check when its done loading?
totem
@totem: "Is the ArrayAdapter loading async?" No.
CommonsWare