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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Trusted Contributor
rrr_04
Posts: 167
Registered: ‎03-02-2010
Accepted Solution

Reboot fail in device

Hello All,

I am trying to reboot device pragmatically. By installing and deleting new module.

 

Application working fine in simulator and but not in device. But it works fine on device if I attach debugger and debug application on device...

 

Any idea what is the problem here. I am following this Thread to reboot device.

 

Thanks in advance

 

Please use plain text.
Developer
peter_strange
Posts: 17,722
Registered: ‎07-14-2008

Re: Reboot fail in device

The fact that it works fine on device if you attach a debugger suggests a timing thing - are you in fact trying to do something on the Event Thread which you need to do on its own Thread?

 

Can you log the statements that are executed in your application to some temporary log (say to the SD Card) and then track the flow of your applicaiton on device without using the debugger.  Compare this flow with what you see when debugging annd that might give you a clue as to what the problem is. 

Please use plain text.
Trusted Contributor
rrr_04
Posts: 167
Registered: ‎03-02-2010

Re: Reboot fail in device

Thanks Peter for your time and suggestion. Yes, I am doing it in event thread. Let me try by its its own Thread... If it will not work, I will try your second suggestion.
Please use plain text.
Trusted Contributor
rrr_04
Posts: 167
Registered: ‎03-02-2010

Re: Reboot fail in device

[ Edited ]

I have implemented code it in different thread from event thread. But its still  not working in device.

I have also print the log and able to find following condition is not true.

                      if (CodeModuleManager.isResetRequired()) {                    
                            CodeModuleManager.promptForResetIfRequired();  // This is not executed when tested it in device                                                                                                       // without debugger but its work fine when

                                                                                                     //attach  debugger               
                    } else {
                        Dialog.alert("Restart fail!");
                    }

 

 

Can you please suggest what is the problem here.


Please use plain text.
Developer
peter_strange
Posts: 17,722
Registered: ‎07-14-2008

Re: Reboot fail in device

I am suspicious when you day that  this is not running on the Event Thread.  If it is not, then this will fail:

Dialog.alert("Restart fail!");

 

Other than that, sorry, no idea.

Please use plain text.
Trusted Contributor
rrr_04
Posts: 167
Registered: ‎03-02-2010

Re: Reboot fail in device

[ Edited ]

 

 

Thanks for your quick reply..

 

Now I got improvement.

 

When I installed app in device, and try to reboot then its not working but after attaching the debugger and try to reboot

 

its working and after removing debugger its started rebooting without debugger. But first time its not working. I need to attach debugger to make it working.

 

I am using following code: -

 

UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {           
                try {
                    byte[] cod = IOUtilities.streamToBytes(getClass()
                            .getResourceAsStream("/restart.cod"));               
                    CodeModuleGroup cmGroup = new CodeModuleGroup(
                            "RestartApp11");
                    int newHandle = CodeModuleManager.createNewModule(
                            cod.length, cod, cod.length);
                    if (newHandle != 0) {
                        int savecode = CodeModuleManager.saveNewModule(
                                newHandle, true);
                        if (savecode == CodeModuleManager.CMM_OK_MODULE_OVERWRITTEN)
                            cmGroup.addModule("restart");
                        cmGroup.store();
                        int[] hand = CodeModuleManager.getModuleHandles();
                        int handleForDelete = 0;
                        for (int i = 0; i < hand.length; i++) {
                            if (CodeModuleManager.getModuleName(hand[i])
                                    .equals("restart")) {
                                handleForDelete = hand[i];
                                break;
                            }
                        }
                        ApplicationDescriptor appDesc[] = CodeModuleManager
                                .getApplicationDescriptors(handleForDelete);
                        ApplicationManager.getApplicationManager()
                                .runApplication(appDesc[0], false);
                        CodeModuleManager.deleteModuleEx(handleForDelete, true);
                    }
                    if (CodeModuleManager.isResetRequired()) {

                        CodeModuleManager.promptForResetIfRequired();

                    } else {
                        Dialog.alert("Restart fail!");

                    }
                } catch (Throwable t) {
                    log("Error while restart device "
                            + t.getMessage().toString());
                }
            }
        });


 

 

 

 

 

Please use plain text.
Trusted Contributor
rrr_04
Posts: 167
Registered: ‎03-02-2010

Re: Reboot fail in device

[ Edited ]

Hello,

 

I found some more information ...

 

When I call CodeModuleManager.deleteModuleEx() to delete a Module, the return value is CodeModuleManager.CMM_OK_MODULE_MARKED_FOR_DELETION using the simulator, but the return value is CodeModuleManager.CMM_OK when I run same application on device without debugger.

 

What is the problem here?

Please use plain text.
Trusted Contributor
rrr_04
Posts: 167
Registered: ‎03-02-2010

Re: Reboot fail in device

 

Hello All,

 

Please help it still not working , i am not sure what is the problem here.

 

I am doing any thing wrong?

Please use plain text.