Reputation: 2998
I want to keep the XMPPConnection open in my application. To achieve that, I thought repeat opening the connection in certain interval of time using AlarmManager
. But my confusion is when and from where I have to initiate that AlarmService
.
Question 1: If I start that AlarmService
from the LaunchActivity
, won't it be scheduled multiple times ?
Question 2: If I start that AlarmService
from any other Activity
or Service, what happens if the user forcefully killed the app ?
Question 3: Creating AlarmService
for same PendingIntent
will replace it(or override it) or it will be scheduled as new one ?
Upvotes: 0
Views: 45
Reputation: 1208
You can start your pending intents from launch activity. The key for pending intent is time, so save the time in UserPrefs
or local DataBase
. And on every launch, before you going to start next pending intent, call alarmManager.cancel(pendingIntent);
to remove the expired intent.
Upvotes: 1