0

I'd like to solve the following problem:

An application displays something via a WebView, but to alert the user when the content has been changed, a notification should be issued that leads the user to the Activity.

The question is: how do I constantly check for updates even though the user probably hasn't even started the application another time? Is that even possible, since I don't think you can have a service starting when the phone boots or something comparable - if any of you have an idea, I'd be grateful to hear it.

Cheers!

davidcesarino
  • 16,160
  • 16
  • 68
  • 109
Tilde
  • 1

1 Answers1

0

Exactly, you answered our own question. You can have service for it. And yes a service can start at boot. All you need to do is create a BroadcastReceiver and register it to receive ACTION_BOOT_COMPLETED. You also need RECEIVE_BOOT_COMPLETED permission. Example :

Manifest:

<receiver android:name=".MyReceiver " android:enabled="true" android:exported="false">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
    </intent-filter>
</receiver>

Code:

public MyReceiver extends BroadcastReceiver {   

    @Override
    public void onReceive(Context context, Intent intent) {

        Intent myIntent = new Intent(context, YourService.class);
        context.startService(myIntent);
    }
}
harshit
  • 3,788
  • 3
  • 31
  • 54