User lock wake delay

I am trying to create a custom lock screen application, but I am not sure if I will do it right. I have a broadcast receiver that listens when the screen is turned on and triggers screen lock activity. This receiver is registered inside the service, which also disables the default lock screen.

The problem is a slight delay between turning on the screen and the activity of the lock screen. How will I do this so that he immediately appears?

My code for the service:

@Override
public void onCreate() {
    super.onCreate();
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    BroadcastReceiver powerReceiver = new PowerReceiver();
    registerReceiver(powerReceiver, filter);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {  

    KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Service.KEYGUARD_SERVICE);
    KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
    lock.disableKeyguard();

    return Service.START_STICKY;
}

@Override
public IBinder onBind(Intent intent) {
    return null;
}

and recipient:

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
        Intent showScreen = new Intent(context, LockScreen.class);
        showScreen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(showScreen);


    }   

}
+1
source share
1 answer

, , .

question .

0

All Articles