Reputation: 1673
I have one requirement to disable the keyguard and turn the screen on when any alarm occurs. Scenario is: My app is running on the foreground,main activity is displaying on the screen and device goes to sleep mode, when any alarm occurs , i have to turned on the screen as well as disable the keyguard, for that i am using flags FLAG_TURN_SCREEN_ON and FLAG_DISMISS_KEYGUARD in onResume method of activity, but as main activity is running on the screen so it seems like it is not calling onresume method of the activity so because of that I am not able to turned on and disable the keyguard. so i would like to know, when screen turned on and if my activity is displaying on the screen then which activity life cycle will get called?
Please help me to understand this issue.
Regards, Piks
Upvotes: 2
Views: 757
Reputation: 3388
here is piece of code in my app hope this help
ALARMRECEIVER.class
public final class ALARMRECEIVER extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent intent2 = new Intent(context,unlock.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent2);
}
}
unlock.class
public void onCreate(Bundle savedInstancestate){
final Window win = this.getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
Upvotes: 1
Reputation: 1934
you will get callback in onResume() when your screen will turn on and the activity will be displayed.
But in your case it wont happen as the activity still has not come to foreground.
Instead of this put some listeners to your specific alarms and then you will get an intent on the events(alarms in your case) and then perform your action.
Upvotes: 0