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
Highlighted
Contributor
Posts: 33
Registered: ‎12-03-2011
My Device: 9800
My Carrier: Blackberry

How to set application enable/disable using checkbox preference .

I have an application.i want to give user a option to enable /disable application by checkbox....i will get store checkbox value in preference.

give me code...thanks in advance.

Developer
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: How to set application enable/disable using checkbox preference .

If I am not wrong you are creating some background component in your application and you want to activate and deactivate your background component by this checkbox, if I am wrong, please specify your problem more precisely.

Contributor
Posts: 33
Registered: ‎12-03-2011
My Device: 9800
My Carrier: Blackberry

Re: How to set application enable/disable using checkbox preference .

I have simple application which show me time after call reject. i want to give user a option....

enable timer application-- by checkbox.

if user click then.then on call reject app run.otherwise not run.

Developer
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: How to set application enable/disable using checkbox preference .

start your timer application/or not according to choice set in checkbox field. What is problem, start your background application, and thread on choice.

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: How to set application enable/disable using checkbox preference .

Add a flag to the persistent storage.

 

Update it according to the user preference and check upon application start-up.

 

E.

Developer
Posts: 455
Registered: ‎03-04-2011
My Device: Paper cup

Re: How to set application enable/disable using checkbox preference .

[ Edited ]

These days users can see what's running in the background, and the more they see there the more likely they are to delete your app if you've left something unnecessarily running.

So I suggest this method, which has been working for me:

1. Make the background app a GlobalEventListener, and create a 'termination' event guid ... i.e. a long int that's a unique string converted to long by right-clicking in the JDE. If that event is received, the background app self-terminates. That lets your foreground app (settings page) terminate the background app if the user changes the 'active' setting.

2. Store the settings in a PersistentObject, with a boolean flag 'autoactivate'

3. The background app has Autostart flag set in the JDE, but checks the settings 'autoactivate' flag; if that is false, it self-terminates during boot-up.

4. The foreground app's settings page shows the current status of the app by checking for presence of its process running; use ApplicationManager.getProcessId() for that, passing in the background app's ApplicationDescriptor which you get from CodeModuleManager.getApplicationDescriptors().

5. If the user deactivates the app by un-checking the 'active' checkbox and saving the new setting, then you terminate it by using ApplicationManager.postGlobalEvent with the termination event GUID. For efficiency, it's best to send that only to the process ID of your background app, which you've already got from checking if it's running earlier.

6. If the user selected the 'activate' checkbox and saved settings when the background app was not already active, then you start it using ApplicationManager.runApplication(), using the ApplicationDescriptor that you've already gotten when you checked if it was running earlier.

 

7. When your background process terminates, make sure it removes the GlobalEventListener; failing to do so might cause an instance of the app to remain in memory.

 

 

Anyway that's how I do it, it works and IMO is better than just leaving the background process running and just checking an 'active' flag. The less stuff left running unnecessarily, the happier the users are.

Contributor
Posts: 33
Registered: ‎12-03-2011
My Device: 9800
My Carrier: Blackberry

Re: How to set application enable/disable using checkbox preference .

thanks but how to check application start-up please give me some code.

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: How to set application enable/disable using checkbox preference .

main function is activated Smiley Happy