Hi all!

I am trying to listen to plug in/out event for headphones while in background. The problem is that while the events are generated in real-time, I am not able to do handle them in real-time. Whatever code I run in the background gets executed all at once when the user opens the app next time. (some main queue problem?)
I want to send location of the user to a server whenever user plugs out headphone when in background.

What should I do for this? I can't spawn a background thread while in background too (it gets spawned after the user opens the app again). Any ideas?

Thanks in advance!

A lot of this sort of stuff is entirely dependent upon the operating system and development tools and api's you are using. So, answering your question is not possible without knowing a lot more about those things, as well as about whether the application is a GUI-based one, or a service-type application with no direct interface to the system's GUI window manager. If the latter, then we also need to know what window manager you are using, if the system is not an MS Windows one.