私のonDestroy
関数でこのコードを実行しています:
@Override
protected void onDestroy() {
if (!(null == theUser.glideId)) {
JSONObject req = new JSONObject();
try {
req.put("actionKey", "UserPresenceInactive");
req.put("userId", theUser.userId);
new ServerRequest().execute(req); //Run an AsyncTask
} catch (JSONException e) {
e.printStackTrace();
}
}
super.onDestroy();
}
私はAsyncTask
サーバーにリクエストを送信します(200の応答で返されます)。
私の質問は、これを行うことの意味(もしあれば)は何ですか?
アクティビティは破棄されますか?サーバーが応答しない場合、アプリは起動したままでANRに入る可能性がありますか?何かご意見は?
編集
代わりにこれを試してみましたが、android.os.NetworkOnMainThreadException
。
new Runnable() {
@Override
public void run() {
JSONObject req = new JSONObject();
try {
req.put("actionKey", "UserPresenceInactive");
req.put("userId", theUser.userId);
new ServerRequest().execute(req); //Run an AsyncTask
} catch (JSONException e) {
e.printStackTrace();
}
}
}.run();
更新#2
Thread
代わりに使用Runnable
してトリックを行いました!