diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c
index 172e832..ec32744 100644
--- a/firmware/target/hosted/android/lcd-android.c
+++ b/firmware/target/hosted/android/lcd-android.c
@@ -69,10 +69,6 @@ void connect_with_java(JNIEnv* env, jobject fb_instance)
java_lcd_init = e->GetMethodID(env, fb_class,
"java_lcd_init",
"(IILjava/nio/ByteBuffer;)V");
-
- native_buffer = e->NewDirectByteBuffer(env,
- lcd_framebuffer,
- (jlong)sizeof(lcd_framebuffer));
have_class = true;
}
/* we need to setup parts for the java object every time */
@@ -118,8 +114,13 @@ Java_org_rockbox_RockboxFramebuffer_surfaceCreated(JNIEnv *env, jobject this,
(void)surfaceholder;
/* Update RockboxFramebuffer_instance */
RockboxFramebuffer_instance = (*env)->NewGlobalRef(env, this);
+ if (native_buffer == NULL)
+ native_buffer = (*env)->NewDirectByteBuffer(env,
+ lcd_framebuffer,
+ (jlong)sizeof(lcd_framebuffer));
+ (*env)->NewGlobalRef(env, native_buffer);
/* possibly a new instance - reconnect */
- connect_with_java(env, this);
+ connect_with_java(env, RockboxFramebuffer_instance);
display_on = true;

send_event(LCD_EVENT_ACTIVATION, NULL);
@@ -141,7 +142,9 @@ Java_org_rockbox_RockboxFramebuffer_surfaceDestroyed(JNIEnv *e, jobject this,
display_on = false;

(*e)->DeleteGlobalRef(e, RockboxFramebuffer_instance);
+ (*e)->DeleteGlobalRef(e, native_buffer);
RockboxFramebuffer_instance = NULL;
+ native_buffer = NULL;
}

bool lcd_active(void)