Search code examples
androidweb-servicesandroid-asynctaskondestroy

How to call webservice (Http Request) when app is killed by swiping in android?


Question/Requirement

How to call Web-Service (HTTP Request) when app is killed by swiping in android?

When I kill application by swiping from recent application list at that time I want to call Web-Service (or AsyncTask).

What I used?

I am trying to call AsyncTask on destroy of activity.

AsyncTask contains WebApi request (using DefaultHttpClient).

Code like this...

@Override
protected void onDestroy() {
    String url = "<webapi-url here>";
    new GetResponse().execute(url);
    super.onDestroy();
}

I am not using any background service.

Used only Activities, not containing any Fragment.

If any solution then please share here.


Solution

  • You can write an Android service component which overrides a method called onTaskRemoved() which will be triggered whenever app is removed by swiping from recents. So you can try this solution and see it fulfills your requirement.