Android, can I put AsyncTask in a separate class and have a callback?

前端 未结 3 1049
一整个雨季
一整个雨季 2020-12-03 02:02

I\'m just learning about AsyncTask and want to use it as a separate class, rather then a subclass.

For example,

class inetloader extends AsyncTask&l         


        
3条回答
  •  醉话见心
    2020-12-03 02:27

    you can pass the activity instance to constructor and call activity function from there...
    Like use interface :

    public interface ResultUpdatable {
    
       public void setResult(Object obj);
       }
    

    Implement this in the Activity and pass in the constructor of Async task and update the result from onPostExecute using setResult function.

提交回复
热议问题