Android AsyncTask and

Hi, I have AsyncTask in my application called in OnCreate (), which retrieves some data over the network and displays an undefined progress bar on startup.

The problem is that when the application starts, the screen remains blank until AsyncTask is finished. The code looks something like this.

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    loadData();
    //Several UI Code   
    startAsyncTasks();
}


 private void startAsyncTasks(){
    new ConnectingTask().execute();
 }
+3
source share
1 answer

OnCreate () is executed before the action is displayed on the screen, so the entire data loading process is performed before the activity is shown.

, AsyncTask OnStart() OnCreate() ( ). OnStart() , (. ).

, , . OnStart() AsyncTask .

:

  • AsyncTask OnStart()
  • , AsyncTask
  • (OnPostExecute())

, OnStart() , (, ). , AsyncTask OnCreate(), - ( ).

, jUnit- AsyncTask - , - -

+1

Source: https://habr.com/ru/post/1773637/


All Articles