onPostExecute没有被调用

我试图onPostExecute()在完成该doInBackground()方法后调用该方法,但未被调用。我怎样才能解决这个问题?

我已经调试了它,并且可以在ArrayList<ItemDTO> data对象中看到数据

感谢您的帮助。

代码

public class GetLLRD {
Context mContext;

public void post_selected(String json, Context context) {
    new MyAsyncTask().execute(json);
    context = this.mContext;
}

class MyAsyncTask extends AsyncTask<String, Integer, List<ItemDTO>> {


    @Override
    protected List<ItemDTO> doInBackground(String... params) {

      .
      .
      .
      .

            Gson gson = new Gson();
            Type listType = new TypeToken<List<ItemDTO>>() {
            }.getType();
            ArrayList<ItemDTO> data = gson.fromJson(sb.toString(), listType);
      .
      .
      .
      .     


        return null;

    }

    protected void onPostExecute(ArrayList<ItemDTO> result) {

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                new MyAsyncTask().execute();
                System.out.println("The method onPostExcute() in GETLLRD class was invoked  again");
            }
        }, 1*30 * 1000);

        if (result != null) {
            Intent intent = new Intent(mContext, Map.class);
            intent.putExtra("list",result);
            mContext.startActivity(intent); 

        }else{
            Log.e("123", "Avoiding null pointer, the dat is null in the GETLLRD class!!!");
        }

    }

}
}
捷美图

onPostExecute 正在被调用。但是,正如其他人指出的那样,您将返回nulldoInBackground且未将数据传递给您的onPostExecute

public void post_selected(String json, Context context) { 
    new MyAsyncTask().execute(json); 
    context = this.mContext; 
} 

class MyAsyncTask extends AsyncTask<String, Integer, List<ItemDTO>> {


    @Override 
    protected List<ItemDTO> doInBackground(String... params) {

      . 
      . 
      . 
      . 

            Gson gson = new Gson(); 
            Type listType = new TypeToken<List<ItemDTO>>() {
            }.getType(); 
            ArrayList<ItemDTO> data = gson.fromJson(sb.toString(), listType); 
      . 
      . 
      . 
      .      


        return data; 

    } 

    protected void onPostExecute(ArrayList<ItemDTO> result) {

        new Handler().postDelayed(new Runnable() {
            @Override 
            public void run() { 
                new MyAsyncTask().execute();
                System.out.println("The method onPostExcute() in GETLLRD class was invoked  again");
            } 
        }, 1*30 * 1000); 

        if (result != null) {
            Intent intent = new Intent(mContext, Map.class);
            intent.putExtra("list",result);
            mContext.startActivity(intent); 

        } 

    } 

} 

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章