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
smotiwala
Posts: 15
Registered: ‎07-26-2008
My Device: Not Specified

Detection of CLDC-application exit or close?

I have CLDC-application, which is background application. I want to detect application exit or destroy or close, so that I will cleanup my resources , persistence store etc.

 

How do I detect? Please help me in this regard.

 

Thanks

Sohail

Please use plain text.
Developer
kzettel
Posts: 120
Registered: ‎07-16-2008
My Device: 9000

Re: Detection of CLDC-application exit or close?

How is your application exiting?  If your application crashes I don't think you can detect it but it if is exiting normally you can just write a cleanup function which gets called by Midlet.destroyApp().

 

If you don't need data to stick around after your app stops running, you don't need to use a persistent store.  You can just keep a static reference to the data and garbage collection will clean it up when your application exits.

Kurt Zettel | Chief Architect | Metova
www.metova.com
Please use plain text.
New Developer
smotiwala
Posts: 15
Registered: ‎07-26-2008
My Device: Not Specified

Re: Detection of CLDC-application exit or close?

Thanx for your reply. Actually my CLDC-application is background service and it extends Application, so I can not use destroyAPP() method of midlet. 

 

Actually I want, when my backgoround service application will uninstall by the user, my application will get notification for uninstalling/removing/closing event or method, so that I'll destroy my persistent object in that method.

 

I found onClose and destroyApp method for UI and midlet application, but still I didn't find any event or property for background service application.

 

Please help me.

 

Thanks

Sohail

Please use plain text.
Developer
kzettel
Posts: 120
Registered: ‎07-16-2008
My Device: 9000

Re: Detection of CLDC-application exit or close?

Unfortunately there isn't any sort of notification in an application when it is uninstalled.  You could implement logic in your second application to occassionally (on a timer task or on startup) which checks to see if the other application is installed or running.  You can check to see if it is installed using CodeModuleManager.getModuleHandel("myBackgroundAppName").  You may be able to check if it is running using ApplicationManager.getVisibleApplications() but it may not return anything if your application is a system app.

 

As far as cleaning up the persistent store, it is handled by the device.  If you are using the PersistentStore it will automatically remove the store if the class of the Object stored is no longer defined.  This means that you can wrap whichever you are storing with a custom object and it will automatically be removed when the application is uninstalled.

 

 

Kurt Zettel | Chief Architect | Metova
www.metova.com
Please use plain text.
Administrator
MSohm
Posts: 14,281
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Detection of CLDC-application exit or close?

To go along with kzettel's suggestion, this link explains how to ensure that persistent data is cleaned up when an application exits.

 

How To - Handle stored data when removing an application
Article Number: DB-00424

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800708/800647/How_To_...

 

 

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
smotiwala
Posts: 15
Registered: ‎07-26-2008
My Device: Not Specified

Re: Detection of CLDC-application exit or close?

Thanks. I have checked my application my persistent objects are cleaned, but one object is not clean.

 

Actually, I have five persistent Objects in my application, one is object array and other four is hashtable. when I uninstall and reinstall my application my four persistent objects are cleaned, but one persistent object is not clean which is hashtable and containing approx 1350 string records.

 

why this object is not clean? I want to trace that is there any exceptions arouses for that persistent object when application will uninstall so that it will not clean? But how do I?

 

Please help me.

 

Thanks

Sohail

Please use plain text.
Developer
kzettel
Posts: 120
Registered: ‎07-16-2008
My Device: 9000

Re: Detection of CLDC-application exit or close?

Hashtable is not an object unique to your application.  Instead of persisting Hashtable you should create a wrapper object.

 

package com.metova.bb.ex.rsa; import java.util.Hashtable; import net.rim.device.api.util.Persistable; public class PersistableHashtable extends Hashtable implements Persistable { }

 

 That way when you remove your application PersistableHashtable will no longer be defined and the stored object will be deleted.

 

 

 

Kurt Zettel | Chief Architect | Metova
www.metova.com
Please use plain text.
New Developer
smotiwala
Posts: 15
Registered: ‎07-26-2008
My Device: Not Specified

Re: Detection of CLDC-application exit or close?

Thanks for reply. I replace Hashtable inwith the above mentioned class (PersistableHashtable) but got the Class Cast Exception.

 

"_persist = PersistentStore.getPersistentObject( PERSIST_KEY );
_PersistItem = (PersistableHashtable) _persist.getContents();"

 

where PersistableHashtable  _PersistItem;

"

Can you please help me

 

Regards

Sohail

 

 

 

Please use plain text.
Developer
kzettel
Posts: 120
Registered: ‎07-16-2008
My Device: 9000

Re: Detection of CLDC-application exit or close?

You still have the old hashtable persisted in your store.  You have to clear it and use your new class going forward.  If you have a lot of devices running this you may want to make code that handles both using instanceof and switches the persisted Hashtabel to your new class when the application starts.
Kurt Zettel | Chief Architect | Metova
www.metova.com
Please use plain text.