diff --git a/android/src/org/rockbox/RockboxActivity.java b/android/src/org/rockbox/RockboxActivity.java
index d8c1307..9c05a9b 100644
--- a/android/src/org/rockbox/RockboxActivity.java
+++ b/android/src/org/rockbox/RockboxActivity.java
@@ -26,6 +26,7 @@ import android.app.Activity;
 import android.app.ProgressDialog;
 import android.content.Intent;
 import android.os.Bundle;
+import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.ViewGroup;
 import android.view.Window;
@@ -54,6 +55,7 @@ public class RockboxActivity extends Activity
         loadingdialog.setCancelable(false);
         startService(intent);
         rbservice = RockboxService.get_instance();
+        
         /* Now it gets a bit tricky:
          * The service is started in the same thread as we are now,
          * but the service also initializes the framebuffer
@@ -74,6 +76,8 @@ public class RockboxActivity extends Activity
                         Thread.sleep(250);
                         if (isRockboxRunning())
                         	break;
+                        else if (rbservice != null)
+                        	rbservice.set_activity(thisActivity);
                         /* if it's still null show the please wait dialog 
                          * but not before 0.5s are over */
                         if (!loadingdialog.isShowing() && i > 0)
diff --git a/android/src/org/rockbox/RockboxFramebuffer.java b/android/src/org/rockbox/RockboxFramebuffer.java
index 84974d6..4123e52 100644
--- a/android/src/org/rockbox/RockboxFramebuffer.java
+++ b/android/src/org/rockbox/RockboxFramebuffer.java
@@ -39,8 +39,7 @@ public class RockboxFramebuffer extends View
     private ByteBuffer native_buf;
     private MediaButtonReceiver media_monitor;
 
-    public RockboxFramebuffer(Context c, int lcd_width, 
-                              int lcd_height, ByteBuffer native_fb)
+    public RockboxFramebuffer(Context c, int lcd_width, int lcd_height, ByteBuffer buf)
     {
         super(c);
         /* Needed so we can catch KeyEvents */
@@ -48,12 +47,15 @@ public class RockboxFramebuffer extends View
         setFocusableInTouchMode(true);
         setClickable(true);
         btm = Bitmap.createBitmap(lcd_width, lcd_height, Bitmap.Config.RGB_565);
-        native_buf = native_fb;
+        native_buf = buf;
         requestFocus();
         media_monitor = new MediaButtonReceiver(c);
         media_monitor.register();
-        /* the service needs to know the about us */
-        ((RockboxService)c).set_fb(this);
+    }
+    
+    public void setNativeBuffer(ByteBuffer fb)
+    {
+    	native_buf = fb;
     }
 
     public void onDraw(Canvas c) 
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
index 8989271..c5736a1 100644
--- a/android/src/org/rockbox/RockboxService.java
+++ b/android/src/org/rockbox/RockboxService.java
@@ -42,6 +42,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.os.IBinder;
+import android.util.DisplayMetrics;
 import android.util.Log;
 
 /* This class is used as the main glue between java and c.
@@ -98,6 +99,19 @@ public class RockboxService extends Service
     	current_activity = a;
     }
     
+    public int get_view_width()
+    {
+        DisplayMetrics metrics = new DisplayMetrics();
+        current_activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
+		return metrics.widthPixels;
+    }
+    public int get_view_height()
+    {
+        DisplayMetrics metrics = new DisplayMetrics();
+        current_activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
+		return metrics.heightPixels;
+    }
+    
 
     private void do_start(Intent intent)
     {
@@ -201,6 +215,15 @@ public class RockboxService extends Service
 		        }
 		
 		        System.loadLibrary("rockbox");
+		        while (current_activity == null)
+		        {
+					try {
+						Thread.sleep(250);
+					} catch (InterruptedException e) {
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+					}
+		        }
                 main();
             }
         },"Rockbox thread");
diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c
index 2747ec2..7df779d 100644
--- a/firmware/target/hosted/android/lcd-android.c
+++ b/firmware/target/hosted/android/lcd-android.c
@@ -21,9 +21,11 @@
 
 
 #include <jni.h>
+#include <stdlib.h>
 #include "config.h"
 #include "system.h"
 #include "lcd.h"
+#include "debug.h"
 
 extern JNIEnv *env_ptr;
 extern jclass  RockboxService_class;
@@ -43,17 +45,28 @@ void lcd_init_device(void)
     JNIEnv e = *env_ptr;
     RockboxFramebuffer_class = e->FindClass(env_ptr,
                                             "org/rockbox/RockboxFramebuffer");
+                                            
+    jmethodID width = e->GetMethodID(env_ptr, RockboxService_class, "get_view_width", "()I");
+    DEBUGF("%d\n", __LINE__);
+    jmethodID height = e->GetMethodID(env_ptr, RockboxService_class, "get_view_height", "()I");
+    DEBUGF("%d\n", __LINE__);
+    lcd_width = e->CallIntMethod(env_ptr, RockboxService_instance, width);
+    DEBUGF("%d\n", __LINE__);
+    lcd_height = e->CallIntMethod(env_ptr, RockboxService_instance, height);
+    DEBUGF("%d\n", __LINE__);
     /* instantiate a RockboxFramebuffer instance
      * 
      * Pass lcd width and height and our framebuffer so the java layer
      * can create a Bitmap which directly maps to it
      **/
-
+    lcd_framebuffer = malloc(lcd_width * lcd_height * sizeof(fb_data));
+    DEBUGF(">>>>>>>>>   %d %d %x\n", lcd_width, lcd_height, lcd_framebuffer);
     /* map the framebuffer to a ByteBuffer, this way lcd updates will
      * be directly feched from the framebuffer */
     jobject buf          = e->NewDirectByteBuffer(env_ptr,
                                                   lcd_framebuffer,
                                                   (jlong)sizeof(lcd_framebuffer));
+    DEBUGF("%d\n", __LINE__);
 
     jmethodID constructor = e->GetMethodID(env_ptr,
                                          RockboxFramebuffer_class,
@@ -61,15 +74,17 @@ void lcd_init_device(void)
                                          "(Landroid/content/Context;" /* Service */
                                          "II"             /* lcd width/height */
                                          "Ljava/nio/ByteBuffer;)V"); /* ByteBuffer */
+    DEBUGF("%d\n", __LINE__);
 
     RockboxFramebuffer_instance = e->NewObject(env_ptr,
                                                RockboxFramebuffer_class,
                                                constructor,
                                                RockboxService_instance,
-                                               (jint)LCD_WIDTH,
-                                               (jint)LCD_HEIGHT,
+                                               (jint)lcd_width,
+                                               (jint)lcd_height,
                                                buf);
 
+    DEBUGF("%d\n", __LINE__);
     /* cache update functions */
     java_lcd_update      = (*env_ptr)->GetMethodID(env_ptr,
                                                    RockboxFramebuffer_class,
@@ -79,22 +94,27 @@ void lcd_init_device(void)
                                                    RockboxFramebuffer_class,
                                                    "java_lcd_update_rect",
                                                    "(IIII)V");
+    DEBUGF("%d\n", __LINE__);
     display_on = true;
 }
 
 void lcd_update(void)
 {
+    DEBUGF("%d\n", __LINE__);
     /* tell the system we're ready for drawing */
     if (display_on)
         (*env_ptr)->CallVoidMethod(env_ptr, RockboxFramebuffer_instance, java_lcd_update);
+    DEBUGF("%d\n", __LINE__);
 }
 
 void lcd_update_rect(int x, int y, int height, int width)
 {
     if (display_on)
     {
+    DEBUGF("%d\n", __LINE__);
         (*env_ptr)->CallVoidMethod(env_ptr, RockboxFramebuffer_instance, java_lcd_update_rect,
                                    x, y, height, width);
+    DEBUGF("%d\n", __LINE__);
     }
 }
 
@@ -173,12 +193,16 @@ void lcd_blit_yuv(unsigned char * const src[3],
 
     if (LCD_WIDTH >= LCD_HEIGHT)
     {
+        DEBUGF("%d\n", __LINE__);
         dst     = LCD_PIXEL(x, y);
+        DEBUGF("%d\n", __LINE__);
         row_end = dst + width;
     }
     else
     {
+        DEBUGF("%d\n", __LINE__);
         dst     = LCD_PIXEL(x, LCD_WIDTH - y - 1);
+        DEBUGF("%d\n", __LINE__);
         row_end = dst + LCD_WIDTH * width;
     }
 
diff --git a/firmware/target/hosted/android/system-android.c b/firmware/target/hosted/android/system-android.c
index 7d1fe9d..71fad88 100644
--- a/firmware/target/hosted/android/system-android.c
+++ b/firmware/target/hosted/android/system-android.c
@@ -22,7 +22,8 @@
 
 #include <jni.h>
 #include "config.h"
-#include "system.h"
+#include "system.h".
+#include "debug.h"
 
 void system_exception_wait(void) { }
 void system_reboot(void) { }
@@ -56,6 +57,7 @@ Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this)
     env_ptr = env;
     RockboxService_instance = this;
     RockboxService_class = (*env)->GetObjectClass(env, this);
+    DEBUGF("Staring the native code\n");
 
     /* no better place yet, most of powermgmt.c is #ifdef'd out for non-native
      * builds */
