Android show ProgressDialog until activity UI fini

2020-07-18 08:23发布

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,

2条回答
闹够了就滚
2楼-- · 2020-07-18 08:57

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...");
    }

}    
查看更多
虎瘦雄心在
3楼-- · 2020-07-18 09:07

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.

查看更多
登录 后发表回答