Return value from AsyncTask class onPostExecute method

前端 未结 3 2060
南笙
南笙 2020-11-27 05:50

Ok so now I have Class A that contains some spinners that values will be populated by Class B that extends AsnycTask which grabs the s

3条回答
  •  误落风尘
    2020-11-27 06:24

    Problem here is that when you execute your AsynchTask, its doInBackground() methode run in separate thread and the thread that have started this AsynchTask move forward, Thereby changes occur on your variable by AsynchTask does not reflect on parent thread (who stated this AsynchTask) immediately.

    Example --

    class MyAsynchTask
    {
    
    doInbackground()
    {
    a = 2;
    }
    
    }
    
    
    int a = 5;
    
    new MyAsynchTask().execute();
    

    // here a still be 5

提交回复
热议问题