[android-developers] Re: options menu problems with SurfaceView and ListView

2010-07-09 Thread javelin21
I found the problem. The Lunar Lander template I was using overrode
onWindowFocusChanged which paused the SurfaceView while the background
threads getting images kept going. This caused everything to get out
of synch. The Lunar Lander is designed to take up the whole screen and
mine is not. I commented out the pause and everything works. Still
some issues with the ListView, but I think I can handle that. The
lesson here is to be sure you understand everything going on in a
template before using it.

Thanks

On Jul 7, 10:27 am, javelin21 dsma...@javelin21.com wrote:
 In my application, I have extended SurfaceView and ListView. I create
 a LinearLayout as below

         mainForm = new LinearLayout(this);
         mainForm.setOrientation(LinearLayout.VERTICAL);
         mainForm.setLayoutParams(new LinearLayout.LayoutParams(
                 LinearLayout.LayoutParams.FILL_PARENT,
                 LinearLayout.LayoutParams.FILL_PARENT));

 I then add the SurfaceView and ListView to the mainForm and then

 setContentView(mainForm);

 I also override onPrepareOptionsMenu and call menu.clear() and then
 dynamically create menus each time the menu button is pressed by the
 user.

 The application loads fine and the SurfaceView works fine as I
 directly draw images to it in a sleep loop.

 The ListView displays items and is desined to refreshed with new
 items.

 The options menu also displays once as well.

 However, once the SurfaceView is running and the ListView is loaded, a
 second call to onPrepareOptionsMenu by pressing the menu key disrupts
 the SurfaceView drawing, causing it to get stuck on the last image it
 was drawing. But the list view does refresh the adapter to change
 content once. After that, the application is hung and the SurfaceView
 keeps playing the same images in a random order.

 I am using runOnUiThread to update the views in the mainForm
 (LinearLayout) and the Lunar Landing template for the SurfaceView as
 shown below

 In Activity

 public void ViewsUpdate() {
         System.out.println(Before ViewsUpdate method);
         runOnUiThread(new updateDoer());

 }

 public class updateDoer implements Runnable {

         public updateDoer(){

         }

         public void run() {

                 contentDone2();
                 viewForm.invalidate();
 //viewForm is where the ListView and other views are added

         }

 }

 In SurfaceView
 private void drawSurfaceView(){
                 Canvas c = null;
             try {
                 c = mSurfaceHolder.lockCanvas(null);
                 synchronized (mSurfaceHolder) {
                     if (mMode == STATE_RUNNING)
                     doDraw(c);
                 }
             } finally {
                 // do this in a finally so that if an exception is
 thrown
                 // during the above, we don't leave the Surface in an
                 // inconsistent state
                 if (c != null) {
                     mSurfaceHolder.unlockCanvasAndPost(c);
                 }
             }

         }

 I am at a loss as to why everything gets clobbered after the options
 menu is built and displayed the second time.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] options menu problems with SurfaceView and ListView

2010-07-07 Thread javelin21
In my application, I have extended SurfaceView and ListView. I create
a LinearLayout as below


mainForm = new LinearLayout(this);
mainForm.setOrientation(LinearLayout.VERTICAL);
mainForm.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));

I then add the SurfaceView and ListView to the mainForm and then

setContentView(mainForm);


I also override onPrepareOptionsMenu and call menu.clear() and then
dynamically create menus each time the menu button is pressed by the
user.

The application loads fine and the SurfaceView works fine as I
directly draw images to it in a sleep loop.

The ListView displays items and is desined to refreshed with new
items.

The options menu also displays once as well.

However, once the SurfaceView is running and the ListView is loaded, a
second call to onPrepareOptionsMenu by pressing the menu key disrupts
the SurfaceView drawing, causing it to get stuck on the last image it
was drawing. But the list view does refresh the adapter to change
content once. After that, the application is hung and the SurfaceView
keeps playing the same images in a random order.

I am using runOnUiThread to update the views in the mainForm
(LinearLayout) and the Lunar Landing template for the SurfaceView as
shown below

In Activity

public void ViewsUpdate() {
System.out.println(Before ViewsUpdate method);
runOnUiThread(new updateDoer());
}


public class updateDoer implements Runnable {

public updateDoer(){

}

public void run() {

contentDone2();
viewForm.invalidate();
//viewForm is where the ListView and other views are added

}
}

In SurfaceView
private void drawSurfaceView(){
Canvas c = null;
try {
c = mSurfaceHolder.lockCanvas(null);
synchronized (mSurfaceHolder) {
if (mMode == STATE_RUNNING)
doDraw(c);
}
} finally {
// do this in a finally so that if an exception is
thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (c != null) {
mSurfaceHolder.unlockCanvasAndPost(c);
}
}

}

I am at a loss as to why everything gets clobbered after the options
menu is built and displayed the second time.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en