Good day.I have horrible situation.I am creating an location share logic within session.I keep that session on server on the mysql.When android hits on that activity,i insert accordingly user information.When android leaves the activity ofcourse i delete that column so the session is abandoned for opposite side.All is great until one issue.Android does not provide an callback for app being swiped from recents,meanging app was killed completelly.I have found an work around there.I am using an service and starting service as soon as it reaches my desired activity.In service i have simple thing called onTaskRemoved() which notifies me as soon as the app was killed by swiping it from recents.All good until the point where i want to call to my server in order to remove the column.The call will not just get through,i will never receive any response there,but in onDestroy() everything working as expected.Actually here is the code
@Override
public void onTaskRemoved(Intent rootIntent) {
destroySession();
super.onTaskRemoved(rootIntent);
}
private void destroySession() {
Log.d("Fsafasfsafasfas", "destroySession: " + opponentId + " my user id" + sharedHelper.getUserId());
Call<ResponseBody> locationCall = Retrofit.getInstance().getInkService().requestFriendLocation(sharedHelper.getUserId(), opponentId, "", "", Constants.LOCATION_REQUEST_TYPE_DELETE);
locationCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response == null) {
destroySession();
return;
}
if (response.body() == null) {
destroySession();
return;
}
try {
String responseBody = response.body().string();
Log.d("Fsafasfsafasfas", "onResponse: " + responseBody);
JSONObject jsonObject = new JSONObject(responseBody);
boolean success = jsonObject.optBoolean("success");
if (success) {
stopSelf();
} else {
destroySession();
}
} catch (IOException e) {
stopSelf();
e.printStackTrace();
} catch (JSONException e) {
stopSelf();
e.printStackTrace();
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
destroySession();
}
});
}
The call will never get through i guess as the only log which is printed,is the id's logs and nothing more..Anyone have a clue whats going on?and how can i handle this situation?