promptForResetIfRequired vs requestPowerOff


When trying to self remove our application using following code, the application is not removed if we don't Device.requestPowerOff (false) but the application is deleted if we CodeModuleManager.promptForResetIfRequired (). PowerOff Yes! = Reset?

So my question is, is there a way to do a reset programtic which will remove our application? Or I do something wrong to do an auto delete in our application?

What's going on




Thanks for your time.


ApplicationDescriptor ad = ApplicationDescriptor.currentApplicationDescriptor();int moduleHandle = ad.getModuleHandle();int rc = CodeModuleManager.deleteModuleEx(moduleHandle, true);

switch (rc)         {                        case CodeModuleManager.CMM_OK_MODULE_MARKED_FOR_DELETION:                CodeModuleManager.promptForResetIfRequired();                //Device.requestPowerOff( false );                break;            case CodeModuleManager.CMM_OK:                //do something                break;                        case CodeModuleManager.CMM_MODULE_IN_USE:            case CodeModuleManager.CMM_MODULE_IN_USE_BY_PERSISTENT_STORE:                //do something                break;            case CodeModuleManager.CMM_HANDLE_INVALID:                                //do something                break;            case CodeModuleManager.CMM_MODULE_REQUIRED:                                //do something                break;            default:                //do something                break;        }

You're right, power off is not the same as reset.  Power off suspends the running applications and puts the BlackBerry in a mode "standby".  When it is powered applications RESUME from where they left.  This is the same as the power on/off a BlackBerry using the power button or red end (varies by model).  The BlackBerry may feeding on almost instantly to this State.

A reset looks more closely to remove and reinsert the battery.  This stops all applications and the JVM.  When you restart the BlackBerry, the JVM restarts with automatic startup applications.  This process takes a few minutes.

If promptForResetIfRequired produces true, it means that the BlackBerry is unable to class cod until the BlackBerry is restarted.  The link below lists the reasons why this can happen.

-The reason for which reset is required when you upgrade an application
Article number: DB-00602

Tags: BlackBerry Developers

Similar Questions

  • Implementing custom listener for ListField

    I'm trying to implement a listener for a custom field I created that would launch a new screen when you click on the field. However, nothing happens when I click on the custom field. I use BlackBerry Java plug-in for Eclipse, JDK 1.3 and JRE 6.0. All my code is attached. contains the code where I'm trying to implement a function fieldChanged.

    package mypackage;
    import net.rim.device.api.system.CodeModuleManager;
    import net.rim.device.api.ui.UiApplication;
     * This class extends the UiApplication class, providing a
     * graphical user interface.
    public class MyApp extends UiApplication
         * Entry point for application
         * @param args Command line arguments (not used)
        public static void main(String[] args)
            // Create a new instance of the application and make the currently
            // running thread the application's event dispatch thread.
            MyApp theApp = new MyApp();
         * Creates a new MyApp object
        public MyApp()
            // Push a screen onto the UI stack for rendering.
            pushScreen(new MyScreen());
    package mypackage;
    import net.rim.device.api.ui.container.*; //for vertical manager
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.FieldChangeListener;
    import net.rim.device.api.ui.Manager;
    //import net.rim.device.api.ui.Screen;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.decor.BackgroundFactory;
     * A class extending the MainScreen class, which provides default standard
     * behavior for BlackBerry GUI applications.
    public final class MyScreen extends MainScreen
         * Creates a new MyScreen object
        private CustomField cField;
        public MyScreen()
            // Set the displayed title of the screen
            setTitle("My New App");
            cField = new CustomField("4.PNG","This is my 4th custom field!!");
            ButtonClickListener listener = new ButtonClickListener();
        }//MyScreen function
        class ButtonClickListener implements FieldChangeListener
            public void fieldChanged(Field field, int context)
                  //we need to determine which button was clicked
                  if(field == cField)
                      new SpeedBumpScreen();
    package mypackage;
    import java.util.Vector;
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    class CustomField extends ListField implements ListFieldCallback {
        private Vector rows;
        public CustomField(String customImg, String customLabel) {
            super(0, ListField.MULTI_SELECT);
            setEmptyString("Hooray, no items here!", DrawStyle.HCENTER);
            Bitmap p1 = Bitmap.getBitmapResource(customImg); 
            rows = new Vector();
            TableRowManager row = new TableRowManager();
            row.add(new BitmapField(p1));
            // SET THE item NAME LABELFIELD
            // if overdue, bold/underline
            LabelField item = new LabelField("item #" + customLabel,
            // overdue
                Font.BOLD | Font.UNDERLINED));
            // SET THE LIST NAME
            row.add(new LabelField("List Name #" + String.valueOf(1),
                DrawStyle.ELLIPSIS) {
                protected void paint(Graphics graphics) {
            // SET THE DUE DATE/TIME
            row.add(new LabelField("Due Date #" + String.valueOf(1),
                    DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
                    | DrawStyle.RIGHT) {
                protected void paint(Graphics graphics) {
        } //end public CustomField()
        // ListFieldCallback Implementation
        public void drawListRow(ListField listField, Graphics g, int index, int y,
                int width) {
            CustomField list = (CustomField) listField;
            TableRowManager rowManager = (TableRowManager) list.rows
            rowManager.drawRow(g, 0, y, width, list.getRowHeight());
        } //end drawListRow()
        private class TableRowManager extends Manager {
            public TableRowManager() {
            } //end pulic TableRowManager
            // Causes the fields within this row manager to be layed out then
            // painted.
            public void drawRow(Graphics g, int x, int y, int width, int height) {
                // Arrange the cell fields within this row manager.
                layout(width, height);
                // Place this row manager within its enclosing list.
                setPosition(x, y);
                // Apply a translating/clipping transformation to the graphics
                // context so that this row paints in the right area.
                // Paint this manager's controlled fields.
                g.drawLine(0, 0, getPreferredWidth(), 0);
                // Restore the graphics context.
            }//end drawRow()
            // Arranges this manager's controlled fields from left to right within
            // the enclosing table's columns.
            protected void sublayout(int width, int height) {
                // set the size and position of each field.
                int fontHeight = Font.getDefault().getHeight();
                int preferredWidth = getPreferredWidth();
                // start with the Bitmap Field of the priority icon
                Field field = getField(0);
                layoutChild(field, 32, 32);
                setPositionChild(field, 0, 0);
                // set the item name label field
                field = getField(1);
                layoutChild(field, preferredWidth - 16, fontHeight + 1);
                setPositionChild(field, 34, 3);
                // set the list name label field
                field = getField(2);
                layoutChild(field, 150, fontHeight + 1);
                setPositionChild(field, 34, fontHeight + 6);
                // set the due time name label field
                field = getField(3);
                layoutChild(field, 150, fontHeight + 1);
                setPositionChild(field, preferredWidth - 152, fontHeight + 6);
                setExtent(preferredWidth, getPreferredHeight());
            }//end sublayout()
            // The preferred width of a row is defined by the list renderer.
            public int getPreferredWidth() {
                return Graphics.BLACK;
            // The preferred height of a row is the "row height" as defined in the
            // enclosing list.
            public int getPreferredHeight() {
                return getRowHeight();
        }// private class TableRowManager extends Manager 
        public Object get(ListField listField, int index) {
            // TODO Auto-generated method stub
            return null;
        public int getPreferredWidth(ListField listField) {
            // TODO Auto-generated method stub
            return 0;
        public int indexOfList(ListField listField, String prefix, int start) {
            // TODO Auto-generated method stub
            return 0;
    } //end class CustomField extends ListField implements ListFieldCallback
    package mypackage;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.component.RichTextField;
    import net.rim.device.api.ui.container.MainScreen;
    public final class SpeedBumpScreen extends MainScreen
         * Creates a new HelloWorldScreen object
            // Set the displayed title of the screen
            setTitle("Speed bump screen");
            // Add a read only text field (RichTextField) to the screen.  The
            // RichTextField is focusable by default. Here we provide a style
            // parameter to make the field non-focusable.
            add(new RichTextField("This is the speed bump screen!", Field.NON_FOCUSABLE));

    In addition, there is nothing in the ListField that will actually generate an event.

    Here is a simple extension to the ListField which will make "clickable".  In your FieldChangeListener you can use getSelectedindex to determine which line has the focus.

    Please ask if this isn't clear:

    public class ClickableListField extends ListField {
        public ClickableListField(int numberOfRows) {
        protected boolean navigationClick(int status, int time) {
            return true;
        protected boolean touchEvent(TouchEvent message) {
            int x = message.getX( 1 );
            int y = message.getY( 1 );
            if( x < 0 || y < 0 || x > getExtent().width || y > getExtent().height ) {
                    // Outside the field
                    return false;
            // If click, process Field changed
            if ( message.getEvent() == TouchEvent.CLICK ) {
                return true;
            return super.touchEvent(message);
  • Do not install manually reboot is no necessary


    I manually install a library package that contain bitmaps. I am able to download and install the cod file, but when I save the new module, the isResetRequired() method returns false.

    Then I launch the application, but no image is displayed. The images are obtained with Bitmap.getBitmapResource (module, name);

    I tried to force the reset of the device with:

    int timeDelay = 1000 * delay;
    ApplicationManager myMgr = ApplicationManager.getApplicationManager();
    ApplicationDescriptor myDsc = ApplicationDescriptor.currentApplicationDescriptor(); 
    Date myDate = new Date();
    myMgr.scheduleApplication(myDsc, myDate.getTime()+timeDelay, true);

    But it doesn't seem to work on Simulator. If I restart (SHIFT + ALT + DELETE) unit (a real) images is displayed without any problem.

    I use OS 4.5 with a Curve 8330.

    If the library has been loaded before the application?  If this is not the case, a reboot may be necessary.  Note that the library itself cannot require a reset (which explains why you see fake) but reset may be required for your application binds to the library (if it is already installed).

  • The blackBerry 10.0 by Application restart


    can we reboot device through the app just as in the java language, we use requestPowerOff in native development can we reboot device is there a way to do that please tell me with code c++ and qml.

    Of course, I don't think that this exists on the native side, to the East, that I have not read anywhere.
    Therefore, your best bet is to make a feature request in BlackBerry bug, information system (SAID / JIRA) using the link above.

  • SystemListener2 never invoked in the present case.

    here is my code. Is there any suggestion? Thanks,
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.container.*;
    import net.rim.device.api.system.*;
    public class DeleteHandle extends UiApplication implements SystemListener2{
        public static void main(String args[]){
            UiApplication app = new DeleteHandle();
        DeleteHandle() {
            pushScreen(new AScreen());
        public void batteryGood() {}
        public void batteryLow() {}
        public void batteryStatusChange(int status) {}
        public void powerOff() {
        public void powerUp() {}
        public void backlightStateChange(boolean on) {}
        public void cradleMismatch(boolean mismatch) {}
        public void fastReset() {
            int handle=CodeModuleManager.getModuleHandle("DeleteHandle");
                    Dialog.alert("Module is being deleted!");
        public void powerOffRequested(int reason) {
            int handle=CodeModuleManager.getModuleHandle("DeleteHandle");
                    Dialog.alert("Module is being deleted!");
        public void usbConnectionStateChange(int state)  {}
        class AScreen extends MainScreen
            public AScreen()
                add(new ButtonField("delete"){
                    public boolean trackwheelClick(int status,int time){
                        return true;
        private void deleteModule()
            int handle=CodeModuleManager.getModuleHandle("DeleteHandle");

    Power off or fast reset is not the same as cold-reset/reboot. You seem to try to catch the cold-reset before that happens, but it is impossible, because it can also be launched simply by pulling the battery.

  • is it possible to install the application without user interaction? in the background?

    Hi, is it possible to do such a thing:

    device ask the server for an application, the server responses and address 'Give me' I can download a *.cod file. is it possible I want to download (and install) without user intervention? I have average-not browser opens, the user clicks on what whether etc application will be downloaded in the background without user interaction? is this possible? and if yes how?


    Use IOUtilities.streamToBytes to read the file directly in a byte array.
    use createNewModule with the byte array to create a new module.
    Use saveNewModule to save the module, enter the promptForResetIfRequired() if necessary.

  • How to remove the app from the blackberry with programming


    I have a blackberry application that works properly when I installled that application I get not all delete option in option > advanced > application.

    Please help me to provide the solution for the removal of the application of the option > advanced options > application.

    I want this because I want to uplaod the application to the blackberry app world.


    Antoine Singh


    Please follow the update here class

    import net.rim.device.api.system.ApplicationDescriptor;
    import net.rim.device.api.system.CodeModuleManager;
    import net.rim.device.api.ui.MenuItem;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.component.Dialog;
    public class UserInterface extends UiApplication{
            Test1 t=new Test1();
        public static void main(String args[])
            UserInterface app=new UserInterface();
        private MenuItem _deleteeMenu = new MenuItem("Delete Tool", 110, 10) {
            // Delete us
            public void run() {
                int actionCode = Dialog.ask("Confirm Deletion",
                        new String [] { "Continue", "Cancel" },
                        new int [] { 0, 1 }, 0);
                if ( actionCode == 0 ) {
                    ApplicationDescriptor ad = ApplicationDescriptor.currentApplicationDescriptor();
                    int moduleHandle = ad.getModuleHandle();
                    int rc = CodeModuleManager.deleteModuleEx(moduleHandle, true);
                    String tellUserMessage = "";
                    if ( rc == CodeModuleManager.CMM_OK_MODULE_MARKED_FOR_DELETION )
                    { CodeModuleManager.promptForResetIfRequired();
                    tellUserMessage = "Please restart the device to remove the application"; } else
                        //              if ( rc == CodeModuleManager.CMM_OK_MODULE_MARKED_FOR_DELETION ) {
                        //                  tellUserMessage = "Please restart the device to remove the application";
                        //              } else
                        if ( rc == CodeModuleManager.CMM_OK ) {
                            tellUserMessage = "Deleted";
                        } else {
                            String errorString = Integer.toString(rc);
                            switch (rc) {
                            case CodeModuleManager.CMM_OK_MODULE_MARKED_FOR_DELETION:
                                tellUserMessage = "Will be deleted on restart";
                            case CodeModuleManager.CMM_MODULE_IN_USE:
                            case CodeModuleManager.CMM_MODULE_IN_USE_BY_PERSISTENT_STORE:
                                tellUserMessage = "Module In Use";
                            case CodeModuleManager.CMM_HANDLE_INVALID:
                                tellUserMessage = "Invalid Handle";
                            case CodeModuleManager.CMM_MODULE_REQUIRED:
                                tellUserMessage = "Module Required";
                                tellUserMessage = Integer.toString(rc);
                            tellUserMessage = "Error Deleting Module: " + tellUserMessage;

    If you want to get the option delete in options > advanced options > application.use the code above.


    Antoine SIngh

  • How to create an application that can withdraw?

    Can someone give an example of source code that is used to remove the application or to update automatically if it has the same application? Thanks before

    Here's the code that remove the currently running the sample Application:

    {} private static deleteUs (boolean confirm) Sub
    ApplicationDescriptor ad = ApplicationDescriptor.currentApplicationDescriptor ();
    If (to be confirmed) {}
    String moduleName = ad.getModuleName ();
    int confirmResult = Dialog.ask (Dialog.D_YES_NO, "confirm delete application module:" + moduleName, Dialog.YES);
    If (confirmResult! = Dialog.YES) {}
    moduleHandle int = ad.getModuleHandle ();
    int deleteResult = CodeModuleManager.deleteModuleEx (moduleHandle, true);
    If (deleteResult! = CodeModuleManager.CMM_OK_MODULE_MARKED_FOR_DELETION) {}
    We expect ' marked for deletion, since we are actually in it!
    Dialog.Alert ("unexpected result delete:" + deleteResult + "\nDelete manually");
    } else {}
    CodeModuleManager.promptForResetIfRequired ();

    I think that you will be able to use one of the standard samples to see how a Menu or button can be used to execute this code.

    It is perhaps not exactly what you want, but it shows you the classes involved in order to investigate documentation and maybe come up with your own variation.

  • Problem updating of application.

    Hi all

    My application is still running in the background.

    I update application automatically using CodemoduleManager, and I got "CodeModuleManager.CMM_OK_MODULE_OVERWRITTEN". But in fact it is not up-to-date. that is old versiom runs on device only.

    I use CodeModuleManager.promptForResetIfRequired (), but it does nothing.

    Then I manually reboot the device by removing the battery, then also older version runs on device only.

    Can someone help me with this?


    If your problem has been resolved then please mark the thread as "accepted solution".

  • Restart the device issue?

    I would like to ask how can I restart BB device throuch java code. I read this article I also tried to use the injectores event:

    EventInjector.invokeEvent(new KeyCodeEvent(KeyCodeEvent.KEY_DOWN, (char)Keypad.KEY_ALT,0,0));         EventInjector.invokeEvent(new KeyCodeEvent(KeyCodeEvent.KEY_UP, (char)Keypad.KEY_ALT,0,0));                   EventInjector.KeyCodeEvent pressCapsKey = new EventInjector.KeyCodeEvent(                 KeyCodeEvent.KEY_DOWN, (char)Keypad.KEY_END,KeypadListener.STATUS_CAPS_LOCK, 0);          EventInjector.KeyCodeEvent releaseCapsKey = new EventInjector.KeyCodeEvent(                   KeyCodeEvent.KEY_UP, (char)Keypad.KEY_END,KeypadListener.STATUS_CAPS_LOCK, 0);            EventInjector.invokeEvent(pressCapsKey);          EventInjector.invokeEvent(releaseCapsKey);
              EventInjector.invokeEvent(new KeyCodeEvent(KeyCodeEvent.KEY_DOWN, (char)Keypad.KEY_BACKSPACE,0,0));           EventInjector.invokeEvent(new KeyCodeEvent(KeyCodeEvent.KEY_UP, (char)Keypad.KEY_BACKSPACE,0,0));

    I did not.

    P.S. My request is signed and after installing it, I can use injectors. Method CodeModuleManager.promptForResetIfRequired () not suits me better. It's the reason to desire return to market through java code.

    This question is asked quite frequently, if you have a search around you can find various discussions.

    There is a 3rd party product that apparently does this, but I don't know of it or how it works.

    I looked at a thread I can find is more, who did something that I thought was clever enough.  Memory, the idea under discussion was to have an application that has been built and signed, once removed, required a reboot - call this Application.  This app was packed inside another application that provided an icon - call this application B.  When the user clicks on the icon of the Application B, B Application will use CodeModuleManager install Application A, and then it removes it, forcing a reboot.

    I don't know to what extent this discussion did, I thought that was established in the Thread code to do this, however I can't find the thread.

    Hope you have better luck.

  • An application can uninstall the itself?

    He has had several discussions on a request for deletion of another by using CodeModuleManager. I am interested in this as a way to deal with that request the removal of the usual way does not clean up the file system: If the application to uninstall, it has the chance to erase his data. Are there special issues involved in a request to remove its own module of code, especially if it is big enough for brother cod files need?

    CodeModuleManager API allows the app delete itself very well. For example, the code below removes the application call (tried on 9000 "BOLD"), if the application consists of a module (with or without siblings module):

  • How can I force a reset of the device?

    My code crushes several modules and also makes changes to the Group module that contains these modules.  I then calls CodeModuleManager.promptForResetIfRequired (), but the BB do not think that a reset is required.  (I also called CodeModuleManager.IsResetRequired (), and he returned false.

    However the new modules I've written are not taking effect until after the BB is reset (I've tested by removing the battery).

    How can I force a reset of the device from my Java code?

    Thank you


    Take a look at this thread. You might get an idea.



  • Uninstall application programmatically


    is there an available API using which we can uninstall our device application.

    We also improve our application running in the background without user intervention?

     if ( rc == CodeModuleManager.CMM_OK_MODULE_MARKED_FOR_DELETION ) { CodeModuleManager.promptForResetIfRequired(); tellUserMessage = "Please restart the device to remove the application"; } else

    To use the promptForResetIfRequired() method, I've changed the code as shown above (I'm sure you can see where it goes).  In this place, the menu item has been restored.

Maybe you are looking for