0

当应用程序被破坏时,我想将注销信息发送到服务器。

这是代码:

@Override
protected void onDestroy() {
    try {
        Log.i("myApp", "Activity destroyed");
        SharedPreferences prefs1 = getSharedPreferences("com.my.app", Context.MODE_PRIVATE);
        Log.i("myApp", "step1");
        String response;
        Log.i("myApp", "step2");
        response = HttpPOSTer.logout(EventCodes.LOGOUT, LOGOUT_EVENTCODE, prefs.getString("sessionID", "null"));
        Log.i("myApp", "step3");
        if (response.equals("logout")) {
            Log.i("myApp", "logged out succesfully");
        } else {
            Log.i("myApp", "couldn't perform logout");
        }
        prefs1.edit().clear().commit();
    }
    catch (InterruptedException e) {
        e.printStackTrace();
    } 
    catch (ExecutionException e) {
        e.printStackTrace();
    }   
    super.onDestroy();  
}

但这是日志,当我从主页按钮的长按菜单关闭应用程序时:

在此处输入图像描述

我什至无法在这里调试。我放置了断点,但在调试时它永远不会被触发。

有什么原因,为什么AsyncTask不被调用onDestroy()

4

1 回答 1

0

在 onDestroy() 中使用 asyntask 不是一个好主意,而是您可以拥有一个扩展 IntentService 的活动并从 onDestroy 调用该活动

于 2013-05-21T11:39:31.903 回答