Android AsyncTask在第二次调用时未执行 [英] Android AsyncTask not executing when called second time
问题描述
我有一个扩展AsyncTask的类
I have a class which extends AsyncTask
public class SendJSONArray2Server extends AsyncTask<String, Void, HttpResponse>
该类将JSONArray发送到服务器,并以JSONArray形式接收响应.我实例化了该类,如下所示:
the class send a JSONArray to the server and receives response as JSONArray. I have instantiated the class as follows
private SendJSONArray2Server sendJSON;
String[] params = { "http://10.0.2.2:8084/xyz/abc",jsonArray.toString() };
sendJSON.execute(params);
在onPostExecute中,我处理用户响应
In onPostExecute I process the user response
@Override
protected void onPostExecute(HttpResponse response)
AsyncTask像魅力一样首次执行,我从服务器收到响应,但是当我第二次尝试将JSONArray发送到服务器时,AsyncTask无法执行.
AsyncTask is executed first time like charm and I am receiving the response from the Server but when I try to send JSONArray to server for the second time AsyncTask does not execute.
我在logcat中没有任何异常或错误.
I am not getting any exceptions or errors in logcat.
推荐答案
为异步任务创建一个单独的实例,然后尝试像这样执行.
Create a seperate instance of your async task and try to execute like this..
new MyAsyncTask().execute(params);
因为 Asynctask只能执行一次(如果尝试第二次执行,则将引发异常)
这篇关于Android AsyncTask在第二次调用时未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!