1

Once the user gets into an activity, I need to send a value to the Web Service and, once s/he exits the activity, I need to send another value to the server. It needs to happen at that exactly moment. Android Developers guide says I should use Foreground Services for background tasks which need to be executed immediately, and WorkManager for deferable tasks. However, I do not need to update anything on the UI nor a notification (as they are mandatory in Foreground services) after the task is done...

What should I use?

mantc_sdr
  • 451
  • 3
  • 17
  • 1
    don't use any of those just send it as immediate request – Fahad Alotaibi Mar 18 '20 at 13:29
  • what object would you use then to send the value to the WebService?? I mean, the background request should be encapsulated into an object able to work in background (askynctask, thread, workmanager, etc...) which one should i use?@FahadAlotaibi – mantc_sdr Mar 18 '20 at 14:24

1 Answers1

-2

UPDATE:

As said in the comment

OnDestroy is not even guarenteed to be called on process death and moreover. The correct approach is a foreground service that shows some generic "syncing with server" message until it's done

Biscuit
  • 4,840
  • 4
  • 26
  • 54
  • what object would you use then to send the value to the WebService?? I mean, the background request should be encapsulated into an object able to work in background (askynctask, thread, workmanager, etc...) which one should i use? – mantc_sdr Mar 18 '20 at 14:23
  • To send request to your API, you could use [Retrofit](https://github.com/square/retrofit). Asynctask are now deprecated – Biscuit Mar 18 '20 at 14:40
  • it is not an API, is a webservice accessed by usihg HttpTransportSE and SoapObject objects @Biscuit – mantc_sdr Mar 20 '20 at 08:46
  • 1
    You can use retrofit to make calls those calls : [post soap xml request with retrofit](https://stackoverflow.com/questions/37825990/post-soap-xml-request-with-retrofit) – Biscuit Mar 20 '20 at 11:38
  • 2
    DON'T do this. OnDestroy is not even guarenteed to be called on process death and moreover. The correct approach is a foreground service that shows some generic "syncing with server" message until it's done. – Andrew G Jul 25 '20 at 20:31