Skip to main content

Trouble using LWUIT 1.5 on Android

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2010-03-15

I've downloaded sources for LWUIT 1.5 along with the Android port from lwuit-incubator (thorsten_s/android folder).

My project buids and stars fine, but I ran into a problem whenever screen orientation changes or I slide out keyboard (I am testing on HTC myTouch 4G).

The test app is very simple

<div>package com.ddTest;</div><div> </div><div>import;</div><div> </div><div>import android.content.res.AssetManager;</div><div>import android.os.Bundle;</div><div>import android.util.Log;</div><div> </div><div>import com.sun.lwuit.Button;</div><div>import com.sun.lwuit.Command;</div><div>import com.sun.lwuit.Display;</div><div>import com.sun.lwuit.Form;</div><div>import com.sun.lwuit.Label;</div><div>import com.sun.lwuit.TextArea;</div><div>import;</div><div>import;</div><div>import;</div><div>import com.sun.lwuit.layouts.BoxLayout;</div><div>import com.sun.lwuit.plaf.UIManager;</div><div>import com.sun.lwuit.util.Resources;</div><div> </div><div>public class LwuitDroidTestActivity extends LWUITActivity {</div><div>    </div><div>    private boolean mFirstTime = true;</div><div>    </div><div>    public LwuitDroidTestActivity() {</div><div>        Log.d(&quot;LwuitTest&quot;, &quot;creating new LWUITActivity&quot;);</div><div>    }</div><div>    </div><div>    /** Called when the activity is first created. */</div><div>    @Override</div><div>    public void onCreate(Bundle savedInstanceState) {</div><div>        Log.d(&quot;LwuitTest&quot;, &quot;onCreate() &quot; + this);</div><div>        super.onCreate(savedInstanceState);</div><div>        </div><div>        Display.init(this);</div><div>    }</div><div>    </div><div>    public void onResume() {</div><div>        super.onResume();</div><div>        </div><div>        Log.d(&quot;LwuitTest&quot;, &quot;onResume() &quot; + this + &quot; mFirstTime=&quot; + mFirstTime);</div><div>        </div><div>        if (mFirstTime) {</div><div>            mFirstTime = false;</div><div>            </div><div>            try {</div><div>                AssetManager am = LWUITActivity.currentActivity.getAssets();</div><div>    </div><div>                InputStream is =;androidTheme.res&quot;);</div><div>    </div><div>                Resources r =;</div><div>                </div><div>                String [] themes = r.getThemeResourceNames();</div><div>                </div><div>                if ((themes != null) &amp;&amp; (themes.length &gt; 0)) {</div><div>                    int index = themes.length - 1;</div><div>                    </div><div>                    UIManager.getInstance().setThemeProps(r.getTheme(themes

));</div><div>                }</div><div>    </div><div>            } catch ( e) {</div><div>            } catch (Exception ex) {</div><div>                System.out.println(&quot;Error parsing resources &quot; + ex);</div><div>            }</div><div>            </div><div>            Form f = new Form(&quot;LWUIT Form&quot;);</div><div>            f.setLayout(new BoxLayout(BoxLayout.Y_AXIS));</div><div>            f.addComponent(new Label(&quot;Hello LWUIT World&quot;));</div><div>            f.addCommand(new Command(&quot;Exit&quot;));</div><div>            </div><div>            f.addCommandListener(new ActionListener() {</div><div>                </div><div>                @Override</div><div>                public void actionPerformed(ActionEvent evt) {</div><div>//set LWUITActivity.FORCE_PROCESS_END_ON_DESTROY flag</div><div>//so that this process will terminate</div><div> </div><div> </div><div>                    FORCE_PROCESS_END_ON_DESTROY = true;</div><div>                    finish();          </div><div>                }</div><div>            });</div><div>            </div><div>            f.addComponent(new Button(&quot;Test Button&quot;));</div><div>            f.addComponent(new TextArea(&quot;Test area\r\nFor text&quot;));</div><div>            </div><div>  ;</div><div>        }</div><div>    }</div><div>}</div><br type="_moz" />

The form shows up initially. It also hadles the case where the Activity is being paused by the Android system. However, when I rotate the phone or slide out the keyboard the screen becomes black and stays like this.

I've tracked the problem down to where Android creates a new instance of my LWUITActivity subclass. The new instance does not have a view attached to it so may be that's why the GUI is never drawn?

I am building with Android 2.2 API 8 using Eclipse 3.6.2 with Android ADT 16.0.0.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-08-15

The android system is restarting your activity on orientation change and keyboard events. You can disable this 'Android 'feature' within the manifest xml. The readme contains a hint:

	 * I strongly suggest using the following attribute within the &lt;activity/&gt; tag in the
* AndroidManifext.xml file:
* android:configChanges=&quot;keyboardHidden|orientation&quot;