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
Regular Contributor
Plato
Posts: 71
Registered: ‎07-11-2010
My Device: Bold 9000
Accepted Solution

Having "something" in PersistentStore requires device restart after upgrade/uninstall ?

hi all,

 

I am trying to identify what is the maximum functionality that can be implemented in BlackBerry application so that upgrade/uninstall does not cause device restart.

 

The official information regarding persistent objects:

 

==== KB ====

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/What_Is...

 

 

...

The application contains a live reference
to a persistent object. ...

 

==== Forum ====

 

http://rim.lithium.com/t5/Java-Development/Error-module-is-in-use/m-p/131618

 

 

....

What exactly does it mean that "The application contains a live reference to a persistent object"? More specifically what does "live" mean?

....

This is an "uncommitted" modified persistent object that is in use by the application.

....


 

 

My current tests show that once you have something saved in PersistentStore, uninstall / upgrade will require device restart. Can somebody please confirm this or explain what's wrong with my test scenario (code to follow) ?

 


-----
A good decision is based on knowledge and not on numbers.
Please use plain text.
Regular Contributor
Plato
Posts: 71
Registered: ‎07-11-2010
My Device: Bold 9000

Re: Having "something" in PersistentStore requires device restart after upgrade/uninstall ?

Environment - real device Bold 9000, OS 5.0, installation was done from local .jad / .cod files (via file system)

 

Test steps:

 

==== scenario 1 ====

1. install the app

2. start the app, select menu / "Increment" several times, exit the app

3. remove battery

4. after restart do not start the app !

5. delete the app

6. device requires "Restart"

 

==== scenario 2 ====

1. install the app

2. start the app, select menu / "Increment" several times, exit the app

3. remove battery

4. after restart do not start the app !

5. install new version of the app

6. device requires "Restart"

 

==== scenario 3 ====

1. after restart on scenario 2

2. start the app, select menu / "Increment" several times

3. select menu / "Remove", exit the app

5. delete the app

6. device does not require "Restart"

 

In scenario 1 and 2 there is one object in PersistentStore, without any direct references to it.

In scenario 3, this object has been removed.

 

Test code can be found below, you can copy&paste and compile it directly.

(I have placed the persistent object in separate file just in case)

 

 

File: RestartTestApp.java

 

 

import net.rim.device.api.ui.*;
import net.rim.device.api.util.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.system.*;


public class RestartTestApp extends UiApplication
{
  RestartTestApp()
  {
    pushScreen(new RestartTestMainScreen());
  }

  public static void main (String args[])
  {
    //Log.info("version 0.02");

    RestartTestApp app = new RestartTestApp();
    app.enterEventDispatcher();
  }
}

class RestartTestMainScreen extends MainScreen
{
  public RestartTestMainScreen()
  {
    super();
    add(new LabelField("Restart Test"));
    add(new LabelField("use menu"));
  }
  protected void makeMenu(Menu menu, int instance)
  {
    super.makeMenu(menu, instance);
    menu.add(menu_increment);
    menu.add(menu_remove);
  }

  private void on_menu_increment()
  {
    //Log.info("on_menu_increment enter");

    // RestartTestApp_storage
    PersistentObject configStore = PersistentStore.getPersistentObject(0xa6c551f290e9ed02L);
    ConfigObject obj;

    synchronized (configStore)
    {
      obj = (ConfigObject)configStore.getContents();
      if (obj == null)
      {
        obj = new ConfigObject(0);
        configStore.setContents(obj);
        configStore.commit();
      }

      int n = obj.getValue();
      obj.setValue(n + 1);
      configStore.commit();
    }
    //Log.info("on_menu_increment obj: " + obj);

    obj = null;
    configStore = null;
    System.gc();
    //Log.info("on_menu_increment exit");
  }

  private void on_menu_remove()
  {
    //Log.info("on_menu_remove enter");
    // RestartTestApp_storage
    PersistentObject configStore = PersistentStore.getPersistentObject(0xa6c551f290e9ed02L);
    ConfigObject obj;

    synchronized (configStore)
    {
      obj = (ConfigObject)configStore.getContents();
      if (obj != null)
      {
        configStore.setContents(null);
        configStore.commit();
      }
    }
    //Log.info("on_menu_remove obj was: " + obj);
    obj = null;
    configStore = null;
    System.gc();
    //Log.info("on_menu_remove exit");
  }

  MenuItem menu_increment = new MenuItem("Increment", 2000, 10){public void run(){on_menu_increment();}};
  MenuItem menu_remove = new MenuItem("Remove", 2000, 10){public void run(){on_menu_remove();}};
}

 

 

File: ConfigObject.java

 

 

import net.rim.device.api.util.*;

public class ConfigObject implements Persistable
{
  private int value;
  ConfigObject(int o)
  {
    value = o;
  }
  public int getValue()
  {
    return value;
  }
  public void setValue(int o)
  {
    value = o;
  }

  public String toString()
  {
    return "[conf] [" + value + "]";
  }
}


 


-----
A good decision is based on knowledge and not on numbers.
Please use plain text.
Developer
geeneeus
Posts: 80
Registered: ‎09-12-2009
My Device: Bold 9700

Re: Having "something" in PersistentStore requires device restart after upgrade/uninstall ?

Not too sure of your issue or what your asking, but a couple things to note are you should use PersistentStore.destroyObject to remove an object rather than just set its contents to null.

 

Also you should never call System.gc() manually unless strictly necessary. Destroying a presistent object will automatically make it viable for garbage collection and the VM will get rid of it itself in its own time. System.gc() (as far as I know) can run lengthy garbage collection operations.

 

Sorry I can't be of more help to what your asking.

Genius Development Scotland
Website: http://www.genius-dev.co.uk
Please use plain text.
Regular Contributor
Plato
Posts: 71
Registered: ‎07-11-2010
My Device: Bold 9000

Re: Having "something" in PersistentStore requires device restart after upgrade/uninstall ?

>  or what your asking

 

My question is simple:

 

"Is it true that if you have even a single Object in Persistent Storage - all upgrades/uninstalls of your app will require device restart ?"

 

It seems to be true in my environment. Can somebody else try the sample code above and let me know what the results are ?

 


-----
A good decision is based on knowledge and not on numbers.
Please use plain text.
Regular Contributor
Plato
Posts: 71
Registered: ‎07-11-2010
My Device: Bold 9000

Can somebody from RIM confirm that persistent objects result in device restart ?

Hello,

 

 Can somebody from RIM confirm or deny this theory ?

 

> "Is it true that if you have even a single Object in Persistent Storage - all upgrades/uninstalls of your app will require device restart ?"

 

 Alternatively - can some of the expert guys (a see some of them around) spend 5 minutes to install my test case on their environments and verify that it behaves the same way there ?

 

 Thanks in advance !


-----
A good decision is based on knowledge and not on numbers.
Please use plain text.
Developer
simon_hain
Posts: 16,189
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Can somebody from RIM confirm that persistent objects result in device restart ?

without a custom object in the store the restart should not be required.

----------------------------------------------------------
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.
@SimonHain on twitter
Please use plain text.
Regular Contributor
Plato
Posts: 71
Registered: ‎07-11-2010
My Device: Bold 9000

Re: Can somebody from RIM confirm that persistent objects result in device restart ?

 


simon_hain wrote:

without a custom object in the store the restart should not be required.


 

  What about single custom object which you do not have live reference to (because app is not started)

 

  According to

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/What_Is...

 

 this should not require device restart.


-----
A good decision is based on knowledge and not on numbers.
Please use plain text.
Developer
simon_hain
Posts: 16,189
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Can somebody from RIM confirm that persistent objects result in device restart ?

i don't have an official document to present, but my (and your own) observations seem to indicate that the linked KB article is not listing all cases.

----------------------------------------------------------
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.
@SimonHain on twitter
Please use plain text.
Regular Contributor
Plato
Posts: 71
Registered: ‎07-11-2010
My Device: Bold 9000

Re: Can somebody from RIM confirm that persistent objects result in device restart ?

[ Edited ]

Thanks for your comment !

 

Is there an unofficial document / thread / whatever that list various observations about when device restart is required after uninstall / upgrade ? (I searched a lot and was not able to find such summary)


-----
A good decision is based on knowledge and not on numbers.
Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Can somebody from RIM confirm that persistent objects result in device restart ?

Your app being started has nothing to do with there being a live reference from your app to persistent store. During system startup, the OS does a lot of analysis of existing modules, whether or not they are flagged to run at startup. During that analysis, it will link the custom object in persistent store to your app's module(s). (This analysis also makes it possible for the system to automatically delete persistent, custom objects that have been orphaned by an application being uninstalled.)

 

As Simon posted, it's not having a persistent object, but having a custom persistent object that forces a restart. Try your experiment using a Hashtable instead of a ConfigObject.

 

Note that the downside of using a generic object class like Hashtable is that your app's persistent data will not go away when your app is deleted.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.