Pergunta

I build an app which fires an activity every time the orientation changes, but I have an exception: I don't want the activity to fire within the next five seconds after phone was unlocked.

So after phone is unlocked I will disregard every phone orientation change for five seconds.
I thought I could get the last-unlock-time and compare it with the current time?

Any suggestions of how to do so?

Thanks!

Foi útil?

Solução

Register a broadcast receiver for ACTION_USER_PRESENT, and start a handler in it to run your activity after a minimum of five seconds.

You'll have to regiester the receiver dynamically, as ACTION_USER_PRESENT is not called if you register from the manifest.

IntentFilter filter = new IntentFilter(Intent.ACTION_USER_PRESENT);
BroadcastReceiver mReceiver = new YourReceiver();
registerReceiver(mReceiver, filter);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top