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
Trusted Contributor
Posts: 182
Registered: ‎09-22-2011
My Device: 9700
My Carrier: airtel

Persisntent object not deleting when handheld restarts

I am building application where i need to store some data as persistent.Its working fine,but when i restart my application,the persistent objcet is not deleted,i want that if i restart my phone,persistent should be removed.Below is my code,plz help.

 

 

package com.imimobile.common;

import net.rim.device.api.crypto.SHA1Digest;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;

public class PersistentStorage {


public PersistentStorage() {
//codeSigningKey = CodeSigningKey.get("DavinciAppshop");
}

public void setObject(String keyString, String val) {
long key = getLongKey(keyString);

PersistentObject pObject = PersistentStore.getPersistentObject(key);

pObject.setContents(val);
pObject.commit();
}

public String getObject(String keyString) {
String object;
long key = getLongKey(keyString);

PersistentObject pObject = PersistentStore.getPersistentObject(key);
object =(String) pObject.getContents();

return object;
}

private long getLongKey(String key) {
SHA1Digest sha1Digest = new SHA1Digest();

sha1Digest.update(key.getBytes());

byte[] hashValBytes = sha1Digest.getDigest();

long hashValLong = 0;

for(int i = 0; i < 10; ++i) {
hashValLong |= ((long)(hashValBytes[i]) & 0x0FF) << (10*i);
}

return hashValLong;
}
}

Developer
Posts: 243
Registered: ‎07-22-2011
My Device: BlackBerry Z10
My Carrier: AirTel

Re: Persisntent object not deleting when handheld restarts

Hi,
When ever app deleted from the device then only persistence will cleared, persistence will not clear when ever restart the device...

If u want to remove your persistence then u have to write manual code only...

----------------------------------------------------------
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.

Trusted Contributor
Posts: 151
Registered: ‎06-17-2010
My Device: Curve 8900
My Carrier: Vodafone

Re: Persisntent object not deleting when handheld restarts

[ Edited ]

hi arunimi123,

if Your persisted data(object) that are defined in the BlackBerry API then your data by default will stay behind
when your application is deleted from the device.

If you used one of your own classes which extends persistable - then it will be deleted when your Application is deleted.

 

Or This will also help you..

 

For delete all data from persistent store use below method.

 

PersistentStore.destroyPersistentObject(key);

 ----------------------------------------------------------

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.

Trusted Contributor
Posts: 182
Registered: ‎09-22-2011
My Device: 9700
My Carrier: airtel

Re: Persisntent object not deleting when handheld restarts

Thank you albert sir,

But i don't know frm where to use 

PersistentStore.destroyPersistentObject(key);
because my requierement is that when the handheld restart the persistant should be removed.And no i m not implementing Peristable
 
Trusted Contributor
Posts: 151
Registered: ‎06-17-2010
My Device: Curve 8900
My Carrier: Vodafone

Re: Persisntent object not deleting when handheld restarts

[ Edited ]

Read this thread and apply in your project...

http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/system/CodeModuleManager.html#...
----------------------------------------------------------
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.

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

Re: Persistent object not deleting when handheld restarts

Hi arunimi123,

 

You can use the SystemListener Interface to check if a device is in power up mode (starting up).

 

In general, your persistent data will remain after restart and if you used your own objects, they will be removed upon application uninstall (objects like Strings will remain in the persistent storage even after application uninstall).

 

I hope that helps,

 

E.

 

 

Trusted Contributor
Posts: 151
Registered: ‎06-17-2010
My Device: Curve 8900
My Carrier: Vodafone

Re: Persistent object not deleting when handheld restarts

Hi arunimi123,

Check out this thread, i think this thread Helps you..

http://supportforums.blackberry.com/t5/Java-Development/Uninstalling-application-programatically/m-p...
----------------------------------------------------------
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.
Trusted Contributor
Posts: 182
Registered: ‎09-22-2011
My Device: 9700
My Carrier: airtel

Re: Persistent object not deleting when handheld restarts

Sir i am using String as object,and as u said,it didnt gt deleted even after the app is deleted.So can u suggest me any turn around for this

Trusted Contributor
Posts: 182
Registered: ‎09-22-2011
My Device: 9700
My Carrier: airtel

Re: Persistent object not deleting when handheld restarts

My requirement is not un-installing the app,but rather if the app is un-installed the persistent datas shoould aslo be removed

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

Re: Persistent object not deleting when handheld restarts

Create class MyString which extends String and use it instead of String.

 

E.