Skip to main content

Last android port and LWUITActvity

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
2 replies [Last post]
bjcoredev
Offline
Joined: 2008-06-13
Points: 0

hi

I ve some problem with the new android port in last SVN

lwuit :Checked out revision 1520.
lwuit incubator Checked out revision 162.

in old way i overloaded the public String getFullApplicationPath() and all worked fine

but now i dont understand the new way

in the doc, it s written

Initialize the LWUIT display with your Android activity in your Activity.onCreate()
method:

Display.init(myactivity);

What is this method ?

Thanks in advance

Reply viewing options

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

Here is an example:

import android.os.Bundle;
import com.sun.lwuit.Display;
import com.sun.lwuit.impl.android.LWUITActivity;
import com.sun.lwuit.io.Storage;
import userclasses.StateMachine;

public class TipsterActivity extends LWUITActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Display.init(this);
        // storage is initialized with activity as parameter!
        Storage.init(this);
        Display.getInstance().callSerially(new Runnable(){

            @Override
            public void run() {
                new StateMachine("/tipster.res");
            }
        });
    }
}

This is the 'Android way' . That is, you extend the android.app.Activity class and onCreate(..) is your entry point. To make things like native menus work you should still extend LWUITActivity (as you did before) which itself extends Activity. If you still want to keep your MIDlet class just call the MIDlet methods from your Activity implementation.

bjcoredev
Offline
Joined: 2008-06-13
Points: 0

Hi thorsten

Thanks for you answer

Look at this code. I want to derive my real activity from this class

If i want to emulate the old way , is this code correct ?

Thx

public class MyTemplateActivity extends LWUITActivity
{
//---------------------------------------------------------------

public abstract String getFullApplicationPath();

private MIDlet midlet;

//---------------------------------------------------------------

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Display.init(this);
Display.getInstance().callSerially
(
new Runnable()
{

@Override
public void run()
{
try
{
midlet = (MIDlet) Class.forName(getFullApplicationPath()).newInstance();
midlet.doStartApp();
}
catch(Throwable _e)
{
shootSelf();
}
}
}
);
}

@Override
protected void onDestroy()
{
Log.d("LWUIT", "onDestroy");
super.onDestroy();
try {
midlet.doDestroyApp(true);
} catch (MIDletStateChangeException e) {
Log.e("LWUIT", "Problem destroying midlet.", e);
}
}

@Override
protected void onPause() {
Log.d("LWUIT", "onPause");
super.onPause();

try {
midlet.doPauseApp();
} catch (MIDletStateChangeException e) {
Log.e("LWUIT", "Problem pausing midlet.", e);
}

}

@Override
protected void onResume() {
Log.d("LWUIT", "onResume");
super.onResume();
/**
* spawn a new thread because we need to wait for the
* views to become visible during initialization and we cannot block this
* thread.
*/
new Thread(new Runnable() {

public void run() {
try {
midlet.doStartApp();
} catch (MIDletStateChangeException e) {
Log.e("LWUIT", "Midlet start failed.", e);
}
}
}).start();

}