09-18-2008 10:51 AM
Working on an app (midlet right now) that we want to periodically "wake up" and sync some data. Is there a way to tell who launched the midlet? (e.g. User-initiated launch or an automatic launch via ApplicationManager.scheduleApplication or PushRegistry.registerAlarm?)
For example, if it is a user-initiated launch, we don't want to run an automatic sync.
Solved! Go to Solution.
09-18-2008 01:44 PM
When you register your alarm, you should also store the time you expect the alarm to go off in the RecordStore (since this is non-volitile persistent storage). When startApp runs, simply compare the current time to the alarm time in your RecordStore. If the alarm time has passed, you know that you were auto started.
One thing to look out for though: We observed that the Blackberry rounds all PushRegistry alarms down to the nearest minute. Also, we found that the alarms fail to run if you pull the battery, power cycle, or lock the keyboard. RealtimeClockListener may be a better way to go, and yes you can still use it in a MIDlet despite what the documentation says (at least on the phones I've tried). Just call Application.getApplication().addRealtimeClockListe
09-18-2008 04:05 PM
We're actually doing this now. Problem is, of course: If the user just happesn to run the app about the same time as the alarm, we don't know if the user launched it or the alarm did. Rare as it may be, would like to avoid this case.