Unsolved QCompass::stop() works strange in Android
-
My app uses QCompass. In simple way user switches compass manually which follows call to compass->start(). After compass starts the system GPS indicator appears in Android taskbar near Wi-Fi connection indicator. That means system compass works. After user switches compass off manually (by tap to button sending signal connected to switching compass slot) the call to compass->stop() forces GPS indicator disappear. This is fine. But compass consumes power when app is suspended in any way (switch to another app, screen off and so on) - Android warns about this. Therefore I made code
void MainWindow::appStateChanged(Qt::ApplicationState state) { if( state == Qt::ApplicationSuspended ) emit sensorsOff(); }
and connected sensorsOff to the same slot for switch compass off when user taps compass button. In code there is no difference how compass is turned off - by user tap or by switch to another application. Signal sends, I see qDebug message in receiver after call to compass->stop(). But the GPS indicator remains in task bar. That means system compass works and consumes power.
The only difference I see is - after button tap application remains active and on top. After status change it is suspended to background. Therefore I tried assemble application with android.app.background_running turned true and false in manifest file. Unfortunately no difference. In both cases system sensor keeps working if slot is called from app state change but shuts down if it is called from tap to button.
Does anybody know how to workaround this? How to force system compass switch off when application is suspended?