Android - Periodically broadcast an event
<p>How do I periodically broadcast an event after user has installed my application.</p>

<p>I have implemented a broadcast receiver which will trigger a task onReceive. Now I need to periodically broadcast this event, so that the task will be executed periodically.</p>

<p>I know I need to use AlarmManager.
The code is somewhat like this.</p>

<pre><code>Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
        this.getApplicationContext(), 234324243, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC, 0, 5*1000, pendingIntent);
</code></pre>

<p>Q1) Where do I place this code if I do not have any Activity? Do I implement this as a service?</p>

<p>Q2) What should be the intent-filter be for my manifest in such a "self created event"?</p>

<p>PS: Actually my current broadcast receiver is waiting for the connectivity change event.   The task is to periodically attempt/try to access the internet. But I cannot solely rely on connectivity change to trigger this task. That's why I need a timer which will either fire this event or trigger the method in onReceive().
I know in this case my intent-filter will be "android.net.conn.CONNECTIVITY_CHANGE"</p>
