0

Whatsapp has a feature like..During call if user terminates (kills the application), the call still continues.

How whatsapp is managing that instance of call and even if click on the notification header it resumes the state of call screen

How can we do that ?

1 Answers1

0

You can achieve it using foreground. A foreground service performs some operation that is noticeable to the user. Foreground services continue running even when the user isn't interacting with the app.

What's app must be using Foreground Service and continue its operation. You can follow this SO for implementation details of such service.

In order to sync the state, you need to maintain the state data required in your ForegroundService. You can start an activity when the ForegroundService's notification is clicked. When activity is created you can bind to service to get the current state and then implement LocalBroadcastReceiver for future updates.

Sagar
  • 23,903
  • 4
  • 62
  • 62
  • Thank you for your reply Sagar...but i have to manage the instance of an Activity. Even the application is closed the Activity's instance should remain on that state (Just like calling functionality of whatsapp) – Karan Lamba Jun 19 '18 at 11:26
  • @KaranLamba You just need to maintain the state data required in your Foreground Service. You can start an activity when the ForegroundService notification is clicked. When activity is created you can [bind to service](https://stackoverflow.com/questions/23017767/communicate-with-foreground-service-android) to get the current state and then register a LocalBroadcastReceiver for future updates. – Sagar Jun 19 '18 at 11:30