I am creating widget app that sync data with server i am registering BroadCastReceiver dynamically for receiving SCREEN_ON and SCREEN_OFF broadcasts i registered my BroadCastReceiver in class that extends Application, but the problem is that if the process is running it app receive SCREEN_ON and SCREEN_OFF broadcasts but if process is died then application would not be able to get receive broadcast why? in BroadCastReceiver theory they says app will receive broadcast even if it is not running.
public class ThisApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Utils.logCat("ThisApplication", "onCreate()");
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
intentFilter.addAction(Intent.ACTION_SCREEN_ON);
registerReceiver(new ScreenOnOffReceiver(), intentFilter);
}
}
public class ScreenOnOffReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
Utils.logCat("Screen ScreenOnOffReceiver", "SCREEN is ON");
}
else
{
Utils.logCat("Screen ScreenOnOffReceiver", "SCREEN is OFF");
}
}
}