Issue
My fundamental problem is figuring out how to determine when my app is put into the background vs undergoing a rotation.
I have an audio recording service that is used for music recognition. I want to intelligently manage the lifetime of this service to accomplish the following:
- Keep the service running during lifecycle events that end up being a device rotation.
- Stop the service when the app is put into the background (to free up the mic).
I can't override onConfigurationChanged
because my app uses actionbar tabs with programatically added fragments and there's no way to re-inflate the fragment layouts.
What is a good way to overcome these challenges? My best solution thus far is updating a timer in the service but I'd like to consider alternatives. I don't like the timer because it's common to have mic contention when using voice search.
Solution
You can call getChangingConfigurations()
or isChangingConfigurations()
in the onPause()
. This would tell you if the orientation is changing. If its not, then its probably going into the background.
Also, you CAN override onCongifurationChanged()
, just make sure you call super.onConfigurationChanged()
so that the orientation change gets handled by the framework.
Answered By - Spidy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.