public class ServerPingWithAlarmManager extends Manager
AlarmManager
.
Smack's PingManager
uses a ScheduledThreadPoolExecutor
to schedule the
automatic server pings, but on Android, those scheduled pings are not reliable. This is because
the Android device may go into deep sleep where the system will not continue to run this causes
In order to use this class you need to call onCreate(Context)
once, for example
in the onCreate()
method of your Service holding the XMPPConnection. And to avoid
leaking any resources, you should call onDestroy()
when you no longer need any of its
functionality.
Modifier and Type | Method and Description |
---|---|
static ServerPingWithAlarmManager |
getInstanceFor(XMPPConnection connection) |
boolean |
isEnabled() |
static void |
onCreate(Context context)
Register a pending intent with the AlarmManager to be broadcasted every
half hour and register the alarm broadcast receiver to receive this
intent.
|
static void |
onDestroy()
Unregister the alarm broadcast receiver and cancel the alarm.
|
void |
setEnabled(boolean enabled)
If enabled, ServerPingWithAlarmManager will call
PingManager.pingServerIfNecessary() for the connection of this
instance every half hour. |
connection
public static ServerPingWithAlarmManager getInstanceFor(XMPPConnection connection)
public void setEnabled(boolean enabled)
PingManager.pingServerIfNecessary()
for the connection of this
instance every half hour.enabled
- public boolean isEnabled()
public static void onCreate(Context context)
context
- public static void onDestroy()