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
Highlighted
Developer
Posts: 384
Registered: ‎08-12-2008
My Device: 8700
Accepted Solution

SystemListener2 never invoked in this 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();
        app.enterEventDispatcher();
    }
    DeleteHandle() {
        Application.getApplication().addSystemListener(this);
        pushScreen(new AScreen());
    }

    public void batteryGood() {}
    public void batteryLow() {}
    public void batteryStatusChange(int status) {}
    public void powerOff() {
        System.out.println("powerOff!");
        Dialog.alert("powerOff!");
    }
    public void powerUp() {}
 

    public void backlightStateChange(boolean on) {}
    public void cradleMismatch(boolean mismatch) {}
    public void fastReset() {
        System.out.println("fastReset");
        int handle=CodeModuleManager.getModuleHandle("DeleteHandle");
        if(handle!=0){
            if(CodeModuleManager.getModuleFlags(handle)==CodeModuleManager.MODULE_FLAG_DELETE)
                Dialog.alert("Module is being deleted!");
        }
        Dialog.alert("fastReset");
        
    }
    public void powerOffRequested(int reason) {
        System.out.println("powerOffRequested");
        int handle=CodeModuleManager.getModuleHandle("DeleteHandle");
        if(handle!=0){
            if(CodeModuleManager.getModuleFlags(handle)==CodeModuleManager.MODULE_FLAG_DELETE)
                Dialog.alert("Module is being deleted!");
        }
        Dialog.alert("PowerOff");
    }
    public void usbConnectionStateChange(int state)  {}


    class AScreen extends MainScreen
    {
        public AScreen()
        {
            super();
            add(new ButtonField("delete"){
                public boolean trackwheelClick(int status,int time){
                    deleteModule();
                    return true;
                }
            });
        }
    }
    private void deleteModule()
    {
        int handle=CodeModuleManager.getModuleHandle("DeleteHandle");
        if(handle!=0){
            CodeModuleManager.deleteModuleEx(handle,true);
            CodeModuleManager.promptForResetIfRequired();
        }
    }
} 

 

 

Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: SystemListener2 never invoked in this case.

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