I studied an Android Development course in the past weeks and I am trying to develop an app.
The app should starts an activity after unlocking the screen from sleep state.
From what I understood, the correct way to implement this function would be through the BroadcastReceiver class, with method onReceive().
From what I understood, any message from Android received through this message should be able to start a foreground activity, right?
Specifically, I wrote:
public void onReceive(Context context, Intent intent) {
Log.d("MyUnlockReceiver", "Received intent: " + intent.getAction());
if (Intent.ACTION_USER_PRESENT.equals(intent.getAction())) {
// some code
}
}
But I get the following message in the logcat:
Background execution not allowed: receiving Intent { act=android.intent.action.USER_PRESENT flg=0x24200010 } to com.remembertobreathe.app/.ScreenUnlockReceiver
I there a way to start a foreground activity (in this case, showing an image) when the unlocking action happens? If not, what kind of workarounds could I use?
I thought that this intent was not considered a background execution.
Best
Luca