Kamalakannan J
Kamalakannan J

Reputation: 2998

Android: When and where to invoke Alarm Service?

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

Answers (1)

Sergey Neskoromny
Sergey Neskoromny

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

Related Questions