Xamarin Android C# ActivityLifecycleCallbacks examples, do they exist?

TimothyTimothy USUniversity ✭✭

I have a need to find a way to accurately track when an application is truly going into the background and coming back to the foreground. The standard OnPause and OnResume won't work in this instance as they aren't always called in only this situation. From what I've been reading, Android has the ability to implement this using ActivityLifeCycleCallbacks. The problem I'm having is that all the examples I'm finding are in Java. As such, I've not found a way to get it to work and convert it into something that can be run in C#. I've posted some links to try and shed some light on exactly what this could look like in Java.

Xamarin Android Docs
https://developer.xamarin.com/api/type/Android.App.Application+IActivityLifecycleCallbacks/

Some other references to implementations of this.
https://stackoverflow.com/a/29999738
https://stackoverflow.com/a/42679191
https://stackoverflow.com/questions/44387737/android-application-lifecycle
https://proandroiddev.com/react-to-app-foreground-and-background-events-with-processlifecycleowner-96278e5816fa
https://medium.com/@iamsadesh/android-how-to-detect-when-app-goes-background-foreground-fd5a4d331f8a

Any additional information would be helpful.

Tagged:

Best Answer

Answers

Sign In or Register to comment.