asynctask快速调用多次?

时间:2015-04-13 06:55:01

标签: android android-asynctask

在我的应用中,user_A可以向user_B发送消息,当user_A向user_B发送消息时,user_B将返回已发送消息的值(状态)。 user_B将状态返回给user_A使用asyntask并且工作得非常好,但是当user_A重复且快速地发送许多消息时,我会遇到问题,自动重复调用asyntask,我收到警告“MessageQueue”

12-31 14:09:33.664: W/MessageQueue(3264): Handler (android.location.LocationManager$ListenerTransport$1) {41403330} sending message to a      Handler on a dead thread
12-31 14:09:33.664: W/MessageQueue(3264): java.lang.RuntimeException: Handler (android.location.LocationManager$ListenerTransport$1) {41403330} sending message to a Handler on a dead thread
12-31 14:09:33.664: W/MessageQueue(3264): at android.os.MessageQueue.enqueueMessage(MessageQueue.java:196)
12-31 14:09:33.664: W/MessageQueue(3264): at android.os.Handler.sendMessageAtTime(Handler.java:473)
12-31 14:09:33.664: W/MessageQueue(3264): at android.os.Handler.sendMessageDelayed(Handler.java:446)
12-31 14:09:33.664: W/MessageQueue(3264): at android.os.Handler.sendMessage(Handler.java:383)

这里是我的代码

private class messageReceived extends AsyncTask<Void, Void, String> {
    private String val; 
    public messageReceived() {
    }

    @Override
    protected String doInBackground(Void... unsued) {
        HttpClient client = new DefaultHttpClient();
        HttpResponse response;
        HttpPost post = new HttpPost("http://myUrl.com/updateSts.php");
        List<NameValuePair> nVP = new ArrayList<NameValuePair>(2);  
        nVP.add(new BasicNameValuePair("msg_id", "023921"));  
        post.setEntity(new UrlEncodedFormEntity(nVP));

        response = client.execute(post);
         val= org.apache.http.util.EntityUtils.toString(response.getEntity());
        return val;
    }

    @Override
    protected void onPostExecute(String val) {
        Log.d(TAG,"posExecuteClass=>"+val);
    }
}

我该如何解决这个问题? 除此之外可能还有其他方法。感谢

0 个答案:

没有答案