Monday, September 23, 2013

How to read file in J2ME using getResourceAsStream

http://stackoverflow.com/questions/7703271/how-to-read-file-in-j2me-using-getresourceasstream

Friday, September 20, 2013

Code SIgning J2ME

The most easy to understand and complete tutorial for J2ME code signing.

http://www.codeproject.com/Articles/85095/How-to-Digitally-Sign-a-J2ME-Midlet

Sunday, July 14, 2013

Res file location

This is somewhat confusing...the res file location must be src.

The code must use the path as-

new StateMachine("/Asha.res");


Thursday, July 26, 2012

Application restarts after incoming call

J2ME/LWUIT application lifecycle causes the application to pause when there is an incoming call or when user minimizes the application. In that case pauseApp() is called on the Midlet. When the application is resumed again, it agains comes to the run() method. If your implementation doesn't handle the lifecycle correctly, it restarts after coming out of pause. The reason is that a normal run() implementation looks likes this-


    public void run() {
       new StateMachine("/myres.res");
    }

This causes a new StateMachine object being created when the app resumes. To over come the problem, use a member variable that holds the StateMachine object and modify the run() method as shown below-

    StateMachine mStateMc = null;



    public void run() {
        if (mStateMc == null) {
            mStateMc = new StateMachine("/myres.res");
        }
    }


This will resolve the app restart issue.

Friday, June 22, 2012

LWUIT reloadForm()

In my app, I wanted to refresh the contents of the form (list). After looking into the UIBuilder source code, I found a method named reloadForm(). It worked as expected i.e. before method and list model init methods were called, however, it didn't put Back button in the refreshed form. To get around the issue, i implemented a method called refreshForm in StateMachine.java and added the back command explicitly. Back command addition code I got from showForm() method in UIBuilder.java. The method is as below-


private void refreshForm() {
        //reloadForm();
        Form currentForm = Display.getInstance().getCurrent();
        Form newForm = (Form) createContainer(fetchResourceFile(), currentForm.getName());
        Command backCommand = currentForm.getBackCommand();
        newForm.addCommand(backCommand, newForm.getCommandCount());
        newForm.setBackCommand(backCommand);
        beforeShow(newForm);
        Transition tin = newForm.getTransitionInAnimator();
        Transition tout = newForm.getTransitionOutAnimator();
        currentForm.setTransitionInAnimator(CommonTransitions.createEmpty());
        currentForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
        newForm.setTransitionInAnimator(CommonTransitions.createEmpty());
        newForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
        newForm.show();
        postShow(newForm);
        newForm.setTransitionInAnimator(tin);
        newForm.setTransitionOutAnimator(tout);
    }

I am not sure if the reloadForm() implementation has bug. I would soon put the issue in the LWUIT issue tracker.

Wednesday, May 30, 2012


Disable back command selectively in form

protected void beforeLandingPage(Form f) {
        // If the resource file changes the names of components this call will break notifying you that you should fix the code
        super.beforeLandingPage(f);
   
        /*
         * Disable back command in Landing Page - we don't want to go to login
         * screen
         */
        Command backCommand = f.getBackCommand();
        f.removeCommand(backCommand);
    }
prevent auto insertion of back command, put following in StateMachine.java --setBackCommandEnabled(false);