My app receives a message from a service, on which it has to perform some processing. Before it can do so, it has to connect to another service (GoogleApiClient). What happens is the app calls onStop before GoogleApiClient returns with connected and therefore i do not process the message.
I acquire a wake lock before i start waiting for googelapiclient onConnected, but it still gets to onStop!
Maybe i misunderstand wake locks. This is what i do:
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelock");
wakeLock.acquire();
I feel uneasy using these wake locks anyhow. if something went wrong it could wind up never released.
Any suggestions appreciated.
A WakeLock is used to keep the phone itself running as not to enter sleep or doze mode. It does not prevent your activity from stopping (onStop) or entirely being closed (onDestroy). Tasks running longer than the activity should be stopped or the results be ignored, since the views they are affecting might no longer be available.
If you have longer running tasks you need to use a Service which will keep running in the background. Here is where you can use a WakeLock so that the service does not get stopped when the user turns the screen off and the service can finish its execution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With