Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
nurikabe
Posts: 44
Registered: ‎08-20-2008
My Device: Not Specified
Accepted Solution

How to tell if an app is launched by the user or automatically?

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.

 

Thanks!

 

Please use plain text.
Developer
MrBawn
Posts: 26
Registered: ‎07-23-2008
My Device: Not Specified

Re: How to tell if an app is launched by the user or automatically?

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().addRealtimeClockListener(clockListener) from within your midlet.

Please use plain text.
New Developer
nurikabe
Posts: 44
Registered: ‎08-20-2008
My Device: Not Specified

Re: How to tell if an app is launched by the user or automatically?

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.

 

Please use plain text.
Developer
KeniF
Posts: 131
Registered: ‎08-13-2008
My Device: Not Specified

Re: How to tell if an app is launched by the user or automatically?

in the same millisecond? Even so one must happen before the other, so don't worry.

Please use plain text.
New Developer
nurikabe
Posts: 44
Registered: ‎08-20-2008
My Device: Not Specified

Re: How to tell if an app is launched by the user or automatically?

Our users have really fast thumbs.  :smileywink:

 

Okay, will give this solution a whirl.

Please use plain text.