Skip to main content

Stuck with Android LWUIT port. Someone help me please.

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
4 replies [Last post]
omar.valerio
Offline
Joined: 2011-08-03

Hi fellow developers,

I should start by saying that I am new to Android development, but I have already around six months experience developing with LWUIT for JME MIDP 2.0. The application I have been working in is about to be ported into Android and I thought it would be nice if I could keep all those nice forms and sweet looking UI. Therefore I read about Android port in the lwuit-incubator forum. I found this interesting and I want to give it a try. I started by downloading the Ant scripts and demo application provided by thorsten_s in his website www.pader-sync.com/lwuit-for-blackberry-and-android.html

So far I have do the following:

I downloaded the sources for LWUIT IO and UI directly from the LWUIT SVN repository as well as thorsten_s Android sources from the LWUIT-INCUBATOR SVN. Then I modified the Ant script provided by thorsten_s to create a LWUIT-Android source port.

<property name="lwuit.repo" value="${basedir}\lwuit\trunk" />
<property name="lwuit.incubator.repo" value="${basedir}\lwuit-incubator\trunk" />

<copy todir="${mysources}" verbose="true">
<!-- LWUIT sources -->
<fileset dir="${lwuit.repo}\IO\src">
<exclude name="**/.svn/**"/>
</fileset>
<fileset dir="${lwuit.repo}\UI\src">
<exclude name="**/.svn/**"/>
</fileset>
<!-- ANDROID sources -->
<fileset dir="${lwuit.incubator.repo}\thorsten_s\android">
<exclude name="**/.svn/**"/>
</fileset>
</copy>

I then follow up by replacing the com.sun.lwuit.impl.ImplementationFactory class from the LWUIT sources with the one provided by thorsten_s

I then create an activity which extend com.sun.lwuit.impl.android.LWUITActivity. and use the onCreate() method to initialize the LWUIT Display.

Because at this point I am trying to first run the SearchListApp example provided by thorsten_s in his website my Android activity look as follows.

import android.os.Bundle;
import com.sun.lwuit.Display;
import com.sun.lwuit.impl.android.LWUITActivity;

public class SearchListActivity extends LWUITActivity implements BaseClass{

private SearchListActivity activity = null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(activity == null){
activity = this;
Display.init(activity);
new SearchListApp(activity).startMyApp();
}
}

public void exitMyApplication() {
this.notifyDestroyed();
}

public final void notifyDestroyed() {
try {
if (LWUITActivity.currentActivity != null) {
LWUITActivity.currentActivity.finish();
}
} catch (Throwable e) {
e.printStackTrace();
}
}

}

After that I have modified the AndroidManifest.xml and now it looks like this.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.java.lwuit.demo.searchlist"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:name="SearchListActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

So far, after performing this step and then compiling the project inside IDE (I am using Netbeans with the Android plugin) i am getting no errors.. I get however some warnings concerning the use of varargs but I guess this is fine. Also there was a complain regarding one overlay method call that I did comment in the AndroidVideo class:

public AndroidVideo(String url, SurfaceView lwuitView) {
super(url);
video = new VideoView(lwuitView.getContext());
// video.setZOrderMediaOverlay(true); // TODO: this line was commented out because compiler complained about that method being missing
video.setVideoURI(Uri.parse(url));
if (nativeController) {
MediaController mc = new MediaController(lwuitView.getContext());
video.setMediaController(mc);
}
nativePeer = (AndroidPeer) PeerComponent.create(video);
}

Since my application is not using the video for anything I guess it's okay if I leave this line out =)

Okay as I final step I run against a VirtualDevice running Android 1.6. I am using the emulator and I was hoping to see something but the application just start to boot and I am immmediately thrown back to the application menu, without any warnings or error messages, either in the device, or in the debug/developer console from my IDE.

So as I told you already in my post title.. I am stuck at this point. I have no idea what to try next and I would happily accept any advise/help you can provide.

Thanks.

Find attached my netbeans project.

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

Hi,

I believe the app is starting and exiting without error because I recently changed the behavior of the implementation and did not update the sample that you downloaded. I still need to update the complete page. For the time being I uploaded the new example and placed it here: http://www.pader-sync.com/LWUITDemo.zip

It is the Tipster demo from the LWUIT SVN repository.

The big difference is that the implementation no longer uses the MIDlet class and you place your implementation directly in your subclass of LWUITActivity. And the build script has been updated because google moved some tools around, breaking the old one.

omar.valerio
Offline
Joined: 2011-08-03

Hi there ts!

Thank you.. It works like charm.. You make my day. =)

hotszkin
Offline
Joined: 2008-11-23

hi,

I tried to do pretty much the same thing as you. But I am new to
android/netbean/ant, don't know how to do. Would you please give me the steps to build the tipster demo.

Thanks

omar.valerio
Offline
Joined: 2011-08-03

Hi Hotskin,

I would proceed like this.

1. Download android SDK. You will need to choose the target platform that you want to download and be ready to wait, because this download really takes some time. After downloading the SDK you will need to create a virtual device. Think about it as an instance in which your application will be running. For this step you will find plenty of documentation and howto proceed in the Android Developer's website.

2. After that you need to install Netbeans. Netbeans already comes with the Ant build system, so you don't need to take care about that. Unless you decide you will be running build files outside from the IDE. But since I assume you just want to get it working fast, you can jumpstart with the Netbeans and go straight to download the Android plugin.

3. The plugin I'm talking about is called Netbeans 4 Android or Android 4 Netbeans.. Right now I cannot remember , but the thing is that you need to install the plugin and please don't forget to also "Activate" it because it is not "active" by default.. Anyway you will find information about how to proceed in the Netbeans developer website. Notice that perhaps the plugin is not available for the latest, newest version of the Netbeans. I am using the plugin for Netbeans 6.5 in Netbeans 7 and it is working fine.

4. Finally just download the zip file provided by thornsten in his reply. It is completely uptodate and you just need to go through the ant build file and make some few edits to have it running for you.. Hmm.. remember to create the Netbeans project using the existing sources but as an Android project.

Regards,

Omar