Issue
I'm looking for a way to detect that my android app has been backgrounded, so that regardless of which Activity was running upon pressing the Home key (or return key on the last activity in stack) then a specified function will be called.
onPause() and onStop() cannot distinguish between a new activity replacing the current one and the app being backgrounded, so I'm looking for advice as to what additional test(s) I must include to ascertain this.
Solution
Using a service, as others have suggested, is the right thing to do.
Broadly, the different Activities that make up your application should all bind to the service in their onResume() method. They should unbind from the service at onPause().
Your service's onUnbind() method will be called when there all the previously connected clients have disconnected, which would be the point where you would drop the Bluetooth connection.
More information about services, and binding to them from activities, at http://developer.android.com/reference/android/app/Service.html.
Answered By - Nik
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.