question

Android avatar image
Android asked

Pausing/Resuming Audio

Currently our app works as follows: - In onPause() pause audio - In onResume() resumes audio As far as I'm aware this is consistent with how the developer docs describe the Activity lifecycle. In particular, the docs state: "If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused." On the Kindle Fire if the user presses the sleep button once, the screen is switched off and onPause() is called. However, when the user presses the sleep button again onResume() is called, but the user is presented with the 'locked screen'. At this point the app is not at all visible - but the audio is resume as described above. Why is onResume() called? And how should we be handling this particular case?
fire tablet
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Jonathan, Sorry for late response. Are you able to solve the issue? The issue is not present in 3rd generation devices. But its reproducible in old devices.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Android avatar image
Android answered
Hi Sujoy, Yes - in fact we did solve this issue. Before resuming the audio we used the KeyguardManager to check whether the lock screen was visible: KeyguardManager kgMgr = (KeyguardManager) getContext().getSystemService(Context.KEYGUARD_SERVICE); boolean isLocked = kgMgr.inKeyguardRestrictedInputMode(); Hopefully this will be useful to other developers.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Good trick. Well done.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.