01-06-2012 04:07 AM
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.
01-06-2012 04:55 AM
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.
01-06-2012 05:05 AM
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.
01-06-2012 05:20 AM
start your timer application/or not according to choice set in checkbox field. What is problem, start your background application, and thread on choice.
01-06-2012 12:58 PM - edited 01-06-2012 12:59 PM
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.