Start Activity in Lock Screen on Marshmellow or Higher devices

I am creating a calling app with sinch service. For Incoming call, i need to unlock lockscreen programatically. Using flag i solved this. but its not working on Nougat.

my current code is in activity:

  @Override
protected void onStart() {
    super.onStart();

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);    }

and on manifest:

 <activity
        android:name="IncomingCallScreenActivity"
        android:noHistory="true"
        android:showOnLockScreen="true"
        android:screenOrientation="sensorPortrait">

    </activity>

1 answer

  • answered 2018-01-16 13:08 MeLine

    From Android O and above, if your application is in the background, your application is allowed to create and run background services for some minutes, afterwards your application will enter in the idle stage, and all background service will be stopped.

    Posible solution is to use JobScheduler api introduced in API21 to perform background tasks.