My goal is to write an app that listens for changes in android calendar. It doesn't seem like there's support for broadcasts in this case, but what's needed is a ContentObserver
.
If I want a ContentObserver
to run indefinitely, it requires a thread to keep running when the app is closed (ultimately I want it to start on mobile boot).
Is a service a good solution for this? Or is it bad having a service running all the time? Will it drain a lot of battery, even though all I will be doing is keeping a ContentObserver
registered?
As far as I can see, my only alternative is to use periodical polling, but I would rather not do that.
It doesn't seem like there's support for broadcasts in this case,
but it does. you must use ACTION_PROVIDER_CHANGED with
android:scheme="content"
android:host="com.android.calendar"
So a receiver with this intent-filter works:
<receiver
android:name=".CalendarChangeReceiver">
<intent-filter>
<action android:name="android.intent.action.PROVIDER_CHANGED"/>
<data android:scheme="content"/>
<data android:host="com.android.calendar"/>
</intent-filter>
</receiver>