How to get a string back from AsyncTask?

前端 未结 8 1993
Happy的楠姐
Happy的楠姐 2020-12-03 04:01

I have the following class:

public class getURLData extends AsyncTask{

@Override
protected String doInBackground(String... pa         


        
8条回答
  •  情深已故
    2020-12-03 04:58

    1. Get the context in the constructor like this:

      public GetDataTask(Context context) {}

    2. Create an Interface with the method:

      void onDataRetrieved(String data);

    3. Implement the Interface in the class from where you are creating the Task object (e.g. MainActivity)

    4. Cast the Context to the Interface and call the onDataRetrieved Method

提交回复
热议问题