BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-10-2009, 06:06 AM   #1 (permalink)
New Member
 
Join Date: Jul 2009
Model: 8300
PIN: N/A
Carrier: No Carrier
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Question PushRegistry throught BlackBerry

Please Login to Remove!

Hi,
Can anybody tell me how to implement PushRegistry throught registerAlarm(),
so, that it will call the same MIDlet after specified time.

I have used the following sample code->

public class AlarmMidlet extends MIDlet implements CommandListener
{
DateField dateField;
Form form;
private static final Command ok= new Command ("OK",Command.OK,1);;

// Command that registers the MIDlet to launch automatically after a certain
// time period
private static final Command REGISTER_TIMER_ALARM_COMMAND = new Command("Register timer alarm", Command.ITEM, 1);

private final String MIDLET_CLASS_NAME;

public AlarmMidlet()
{
MIDLET_CLASS_NAME = this.getClass().getName();
}

public void startApp()
{
form = new Form("Welcome");
form.append("Hello AlarmMidlet");
form.addCommand(ok);
form.addCommand(REGISTER_TIMER_ALARM_COMMAND);
form.setCommandListener(this);
Display.getDisplay(this).setCurrent(form);

System.out.println("startApp");
}

public void pauseApp()
{

}
private void registerTimerAlarm(long timePeriodToAutoStart)
{
// Set the launch time to current time + the specified period
long timeToWakeUp = System.currentTimeMillis() + timePeriodToAutoStart;
long timeToWakeUp1 = System.currentTimeMillis();
System.out.println("Registering the timer alarm...");

try {
PushRegistry.registerAlarm(MIDLET_CLASS_NAME, timeToWakeUp);
System.out.println("Alarm is registered!");
System.out.println("System time:"+timeToWakeUp1);
System.out.println("Total Time :"+timeToWakeUp);
} catch (ClassNotFoundException ex) {
System.out.println(ex.getMessage());
System.out.println("Alarm registration failed.");
} catch (ConnectionNotFoundException ex) {
System.out.println(ex.getMessage());
System.out.println("Alarm registration failed.");
}
notifyDestroyed();
}

public void commandAction(Command command, Displayable displayable)
{
if (command == ok) {
// Exit the MIDlet
destroyApp(true);
} else if (command == REGISTER_TIMER_ALARM_COMMAND) {
//registering timer alarm. Alarm will start MIDlet throught
//30 seconds
registerTimerAlarm(30000);
}
}
public void destroyApp(boolean unconditional)
{

notifyDestroyed();
}
}


But it is not calling the same MIDlet after specified time.

I have used eclipse Version: 3.4.1, J2MEPolish project in which, through build.xml calling BlackBerry8300(BlackBerryJDE4.5.0)


Please help me. :(

Thanks,
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.