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
Developer
cyberia61
Posts: 79
Registered: ‎01-01-2009
My Device: Not Specified
Accepted Solution

Handle stored data on app deletion issues

I just went thru this article

 

Handle stored data when removing an application

 

and a few things are still not clear to me. May be only to me :smileyhappy:

 

It says

 

<When you use the BlackBerry persistence model, data is only deleted if the store contains data that belongs to the removed application.> 

 

Understood. Great. Makes sense.

 

then the next line messes things up , at least for me.

 

<For example, if an application stores an object with a package called com.mycompany.application.storage and no other application on the BlackBerry smartphone makes reference to the package, the persistent store and the removed application are deleted.>

 

Now, by saying an application stores an object with a package called com.mycompany....

the author means an object WITHIN a package or what?

 

The Vector object belongs to java.util.*; package,

and you can use it in your application by importing it into your package.

 

The logic would be:  if  you use a Vector object in your application within your app package to store elements and no other app has reference to that package  the Persistent object containing the Vector object is removed.

 

The other method by wrapping a Vector object into your own class is understood but seems like a hacked up solution.

 

The other issue.

 

No word on how to retain Persistent object if a user wishes so on removing an application.

 

Say, I have an app that stores some data using the Persistent model.

I want to delete it for whatever reason.

 

Now,  on deletion, the app must ask me (the user)

whether I want to remove persistent data or keep it.  A Dialog box,  YES / NO.

 

So, if later I decide to install the same version or a new version, the persistent data is available the the application.

 

Any thoughts on the issue?

Thanks

 

 

 

 

 

 

Please use plain text.
Developer
Aman_vivek
Posts: 216
Registered: ‎02-18-2010
My Device: 9350,8520

Re: Handle stored data on app deletion issues

 


cyberia61 wrote:

 

 

Now,  on deletion, the app must ask me (the user)

whether I want to remove persistent data or keep it.  A Dialog box,  YES / NO.

 


I don't know above is possible or not. 

 

But if you want to delete persistent data, make custom vector and persist that vector(or Custom String ).

I think this may help. For creating a custom vector just make a class and extends vector.

 

Thanks 

Vivek Kumar Srivastava

 

Please use plain text.
Developer
cyberia61
Posts: 79
Registered: ‎01-01-2009
My Device: Not Specified

Re: Handle stored data on app deletion issues

Thanks,

 

about extending the Vector, yes I have pointed out before that it seems a bit of hackish thing to do,

 

to many wrappings, Vector is a wrapper class in its own right.

 

I have not played with it yet, but will tomorrow.

 

After reading again, I think i got what they mean,  by

 

<...stores an object with a package called com.mycompany.application.storage>

 

What they mean, is  when u declare a variable, give it the fully qualified name !

 

Say if you have  an Object obj that is later gonna be put in a Vector which u will persist,

 

name it with the package to which it belongs to  prefix  - com.mypackage.Object obj;  aka the fully qualified name.

 

If u have several objects stored in the Vector , you can just have one with the fully qualified name  that is not used by any other app.  The entire vector will be removed then.

 

if the above holds true, (I will make test runs tomorrow ) then name one object within the Vector with a fully qualified name, that'll do the trick.

 

for primitives the fully qualified name is whatever the type is,   boolean x, or int x, or whatever,

 

but it should not be a problem cuz before u add those to a Vector object you wrap em in whatever objects they correspond to.

 

This is my understanding,  I will be checking it out.

 

I just want to add that it's kinda sorta seems a bit fragile to me, the design of it.

 

Thanx

 

 

 

 

Please use plain text.
Developer
cyberia61
Posts: 79
Registered: ‎01-01-2009
My Device: Not Specified

Re: Handle stored data on app deletion issues

On the issue of a user having an option to keep or delete Persistent data on an application removal.

 

I cannot find a way to do that

 

In my view that's not an application but the System that should do the job.

 

When a user chooses to delete an application, the application is not running.

It's not the application that removes itself, it's the System that removes the application.

 

I would expect the System to detect whether or or not an application references some Persistent data on deletion, and if so, ask a user Do you want to delete whatever associated data or keep it?

 

Well, may be I'm missing something here.

Any thoughts are much appreciated.

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

Re: Handle stored data on app deletion issues

"I would expect the System to detect whether or or not an application references some Persistent data on deletion, and if so, ask a user!

 

Nice idea.  But sorry that is not what it currently does.  An idea for the future.

 

Currently you have two options

a) If you want the data to be removed, then you create a custom class (you hacked solution, though to me it does not seem that hacked)

b) Use a standard class, like Vector, and the data will not be deleted.

 

The option you require is not supported by the OS.  Sorry.

 

There may be a away of doing it in OS 5.0 and above, with a listener that listens for app deletion.  So you can have a standard class in your know place, and have your listener ask the user about deletion.  However some people are having problems getting this to work, search the forum.

Please use plain text.
Developer
cyberia61
Posts: 79
Registered: ‎01-01-2009
My Device: Not Specified

Re: Handle stored data on app deletion issues

Thanks for the response.

 

I  went thru the APIs CodeModuleManager class and CodeModuleListener interface  a few days ago and,  correct me if I'm wrong,  in order to use them the application needs to be running.

 

or some other application has to be active "whose event thread will process the notifications sent to listener "'

 

 

 

 

 

 

Please use plain text.
Developer
cyberia61
Posts: 79
Registered: ‎01-01-2009
My Device: Not Specified

Re: Handle stored data on app deletion issues

... as for getting the Vector object wrapped.

 

That's one of the ways doing it, but we will be creating one more  object that just hangs out there and doesn't do much.

 

The article mentions another approach as well.

 

The same is true if the object is wrapped in a container such as a Vector.

Even if only one of the elements of the Vector has a package name that is not used by other applications, the entire Vector is removed from the persistent store. 

 

I'll go for this one.

I have 3 elements added to a Vector object, I name one element only with the fully qualified name.

 

com.package.subpackage.Object obj = new Object();  // for instance

 

Now we don't need to create a wrapper for the Vector object.

 

 

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

Re: Handle stored data on app deletion issues

You are correct, the Application must be running with an Event Thread, for the Listener to be invoked. 

 

Regarding wrapping, I'm happy with either approach, however I must be honest I don't see a significant difference between having your own Vector or having your own Object.

 

Extending Vector and using that does not create another Object, it creates a different Object.  But whether it is your Vector or the standard Vector, it is still just one Object.  Or have I missed something?

Please use plain text.
Developer
cyberia61
Posts: 79
Registered: ‎01-01-2009
My Device: Not Specified

Re: Handle stored data on app deletion issues

You're right ,  only one object is created of your own type.

Accepted.

 

In the second approach though,  we can use  the java.util.Vector  that gets persisted.

 

This Vector object  needs to have only one element with the fully qualified name,  regardless of how many elements it stores,  to be deleted on the application removal.

 

on the CodeModuleListener.

 

The way it works doesn't help my case unfortunately.

 

The application may have an unistall option in the menu  though,  so  the listener object can receive an event from the CodeModuleManager and do a cleanup.

 

 But isn't it a bit "unorthodox" to have an application to remove itself?

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

Re: Handle stored data on app deletion issues

"But isn't it a bit "unorthodox" to have an application to remove itself?"

 

Agreed, RIM didn't ask me before they decided on their direction in this area - I do not think what they have implemented is very useful! 

Please use plain text.