I have a service from which I instationate my ScreenReceiver class. How can I notify service when OnRecieve method of ScreenReceiver is triggered? I’d like the update() method to be called when ‘onRecieve` is trigerred.
StateChecker.java (draft):
public class StateChecker extends Service {
//...
// setting TimeAlarm
TimeAlarm mTimeAlarm = new TimeAlarm();
mTimeAlarm.SetAlarm(this.getApplicationContext(),10);
public void update() {
//update sth
}
//...
}
ScreenReceiver.java (draft):
public class ScreenReceiver extends BroadcastReceiver {
//...
@Override
public void onReceive(Context context, Intent intent) {
//...
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
}
//...
}
You can probably do something like this:
Make a new
Intentto yourServicefrom theReceiver, passing off an Extra, then overrideonStartCommand()in the Service. Check the intent for the Extra, and if the Extra exists, callupdate().Also, if you use
thisinstead ofthis.getApplicationContext(), it is very likely that yourReceiver‘sonReceive()Contextparameter will be the service. Then you can just cast.Eg