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
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900

Re: local notification based on time selected by the user and shoe msg

look at first pic , for local notification when i click to selectTime a time picker will be open and look at 2nd pic

after selecting the time i display that time in label.
now i want that that selected time will match with the time of phone and when that time is equal i have call my web service to fetch the data and update the app. 

i did not under stand that how should i match that selected time with phone time for eg i have selected 9am, at tommorrow when the phones time is 9 am i want to call my web service , here is my code for time picker

private void createGUI()
{
String st_ar[]={"Select Time"};
choiceField=new ObjectChoiceField("Daily update: ", st_ar)
{
protected boolean navigationClick(int status, int time)
{
try {
DateTimePicker datePicker = DateTimePicker.createInstance( Calendar.getInstance(), null,"hh:mm aa");
datePicker.doModal();
dateStrTime = new StringBuffer();
_timeCal = datePicker.getDateTime();
_timeFormat.format(_timeCal, dateStrTime, null);
label.setText(" "+dateStrTime);

} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("createGUI="+e.getMessage());
e.printStackTrace();
}
return true;
}
};

}

9630.png

2nd pic

9630-01.png

 

Please use plain text.
Developer
peter_strange
Posts: 19,608
Registered: ‎07-14-2008
My Device: Not Specified

Re: local notification based on time selected by the user and shoe msg

[ Edited ]

One question per Thread first.

 

This is a new requirement, please mark this Thread as solved and start a new Thread.

 

Here is some information on doing this:

http://supportforums.blackberry.com/t5/help/faqpage/faq-category-id/solutions#solutions

 

When you post you next question, please post what your requirement, in words and with no redundant code.  For example, in this case, your requirement is to match a time selected.  So the code to select the time is completely redundant.  We don't need it and we don't want it. 

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900

Re: local notification based on time selected by the user and shoe msg

actually this is the same question that i have asked, this is not a different question, i have explained my question that what i want
Please use plain text.
Developer
peter_strange
Posts: 19,608
Registered: ‎07-14-2008
My Device: Not Specified

Re: local notification based on time selected by the user and shoe msg

[ Edited ]

To do this you will need to have some part of your Application always 'active'.  Probably the easiest way to do this is to have an alternate entry point that starts the background processing.  Here is a KB article to help.

 

http://supportforums.blackberry.com/t5/Java-Development/Set-up-an-alternate-entry-point-for-an-appli...

 

You will find more about this if you search the forum, people often ask questions about auto-start and alternate entry.

 

From there, you need something that will trigger your application.  Probably the easiest way to do this is to use the RealTimeClockListener interface.  You set this up and your application will get bumped every minute.  Then you can check to see if your alarm time has in fact passed.  Look up the API for information on using this Interface.

 

Finally you will need to notify the user, perhaps using an icon change, perhaps something more dramatic:

http://supportforums.blackberry.com/t5/Java-Development/Alert-a-BlackBerry-smartphone-user-from-a-Ba...

 

I have had problems changing the icon for my application in situations on OS 5.0 like this because the background processing is not actually associated with the icon.  So you will need to test this yourself. 

 

That is one approach.  There are many others using Threads and Times and autostarting your application, but this is the approach I would use. 

 

As you can see there are lots of individual parts to this.  I think it would be appropriate to mark this Thread as solved and then start a new Thread if you have an issue with a specific part of the development. 

 

OK?

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900

Re: local notification based on time selected by the user and shoe msg

that was looking very difficult ,i'll try and i'll notify if this work for me
Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900

Re: local notification based on time selected by the user and shoe msg

i have read the first link but i did not understand the following code to run app in background
public static void main(String[] args) {
if ( args != null && args.length > 0 && args[0].equals("gui") ){
// code to initialize the app
theApp.enterEventDispatcher();
} else {
// code to launch the background thread }
}
}
Please use plain text.
Developer
simon_hain
Posts: 16,207
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: local notification based on time selected by the user and shoe msg

the alternate entry point sets up another project (included in the main project) that starts your program with an argument.
in this case the argument is "gui" and used by the main entry point, and if no argument is present the else clause is executed.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900

Re: local notification based on time selected by the user and shoe msg

if i used RealTimeClockListener interface , that will check time every minute, i'm worry about battery drain problem.
Please use plain text.
Developer
simon_hain
Posts: 16,207
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: local notification based on time selected by the user and shoe msg

what should drain the battery? the listener is triggered by the system, if it does nothing there is no battery drain...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900

Re: local notification based on time selected by the user and shoe msg

i hv used this code to get the time on every minute works fine it give me time on evry minute but if i close the app then it's not working,i mean after closing the app how would i run that code in background.to get the time

public class BackgroundApp extends UiApplication implements RealtimeClockListener
{
/**
* Entry point for application
* @param args Command line arguments (not used)
*/
public static BackgroundApp theApp=null;
public static void main(String[] args)
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
theApp = new BackgroundApp();
theApp.enterEventDispatcher();
}


/**
* Creates a new MyApp object
*/
public BackgroundApp()
{
// Push a screen onto the UI stack for rendering.

addRealtimeClockListener(this);
}


public void clockUpdated() {
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
int minute = Calendar.getInstance().get(Calendar.MINUTE);
System.out.println(""+hour+":"+minute);



}
}

Please use plain text.