Hi all. I have a problem. Please help.

1. I use a multiple views.

Main menu surface view:
<view
class="com.sniko.simplepong.MainMenuActivity$MainMenuSurfaceView" 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:scrollbars="vertical"
android:fadingEdge="vertical" />
Main menu surface  class: 
public static class MainMenuSurfaceView extends SurfaceView implements 
SurfaceHolder.Callback {
    public static MainMenuThread drawThread;
    public MainMenuSurfaceView(Context context) {
        super(context);
        getHolder().addCallback(this);
    }
    
    public MainMenuSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        getHolder().addCallback(this);
    }
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
     int height) { 
    }
    public void surfaceCreated(SurfaceHolder holder) {
        drawThread = new MainMenuThread(getHolder(), getResources(), 
getWidth(), getHeight());
        drawThread.setRunning(true);
        drawThread.start();
    }
    public void surfaceDestroyed(SurfaceHolder holder) {
        boolean retry = true;
        // end thread work
        drawThread.setRunning(false);
        while (retry) {
            try {
                drawThread.join();
                retry = false;
            } catch (InterruptedException e) {
                // try one more time
            }
        }
    }    
}
Main menu thread:  
public class MainMenuThread  extends Thread
{
 int _fps = 60;
int _sleepTime = 1000/_fps;
 Core _core;
 private static boolean runFlag = false;
    private SurfaceHolder surfaceHolder;
    public MainMenuThread(SurfaceHolder surfaceHolder, Resources resources, 
int width, int heigh)
    {
        this.surfaceHolder = surfaceHolder;
        _core = new Core(width, heigh);
    }
    public void setRunning(boolean run) {
        runFlag = run;
    }
    
    @Override
    public void run() {
        Canvas canvas = new Canvas();
        while (runFlag) 
        {
            try 
            {
                canvas = surfaceHolder.lockCanvas(null);
                synchronized (surfaceHolder) 
                {
                canvas.drawRGB(176, 196, 222);
                Thread.sleep(_sleepTime);
                _core.DrawMenuBackground(canvas);
                }
            } 
            catch (InterruptedException e) 
            {
// TODO Auto-generated catch block
e.printStackTrace();
} 
            finally 
            {
                if (canvas != null) 
                {
                    surfaceHolder.unlockCanvasAndPost(canvas);
                }
            }
        }
    }
}

And another similar for options menu. I use multiple threads and surface 
view because is use 1 surface and thread class I have the next situation:
When application starts, surface view start and create thread for drawing 
on it. When I click options button application goes to options menu and as 
I understand
starts another thread and after few seconds options thread is stop (I think 
because menu surface surfaceDestroyed method is executed). By why? I was 
thinking that 
options activity and  surface view create a new thread object and it 
independent from menu thread. That's why I use multiple threads and surface 
view classes. If anyone knows how
to do more simpler and faster please help!

2. So and when I start to use multiple views and threads when on options 
menu I click back button it goes on main menu, little luggy (I think that 
in this time options menu thread and surface view not dispose) 
and then works normal (I think at that moment "garbage collector" kill 
thread or surface). So how can I avoid this.

Thanks all answers!.





-- 
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

Reply via email to