Вопрос

When i unlock my device to see my application, the process in onResume() is launched. How do I cancel the events of unlock, to avoid onResume() from processing?

Это было полезно?

Решение 2

To prevent unlock your device use below flag in your activity.

WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON 

Code

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Note :

As stated on the Activity lifecycle docs, onCreate and onResume will always both be called the first time an Activity is started. When going back to Activity, at least onResume will be called

Другие советы

OnResume is always called when your Activity was in background (e.g. other App, Lockscreen, Homescreen... is shown).
Look at the Activity Life Cycle to check if you can move your code from onResume() maybe to onStart() to fix your issue.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top