2010-07-20 77 views
1

我有2班GLLayerGLCamTest。我试图运行位于GLCamTest的方法...我如何在这里实现一个处理程序?

 public Bitmap extractimage(int pos){ 
    LocationData tweets; 
    tweets = new LocationData(this); 
    SQLiteDatabase db = tweets.getWritableDatabase(); 
    //select the data 
    String query = "SELECT * FROM tweets;"; 
    Cursor mcursor = db.rawQuery(query, null); 
    //Move to Position specified. 
    mcursor.moveToPosition(pos); 

    //get it as a ByteArray 
    byte[] imageByteArray=mcursor.getBlob(7); 
    //the cursor is not needed anymore 
    mcursor.close(); 

    //convert it back to an image 
    ByteArrayInputStream imageStream = new ByteArrayInputStream(imageByteArray); 
    Bitmap theImage = BitmapFactory.decodeStream(imageStream); 
    return theImage; 
    } 

我期待从GLLayer,但是从我的理解,我需要一个处理器上的线程来运行..

  public void run() { 
    GLCamTest cam = new GLCamTest(); 
    image = cam.extractimage(q); 

} 

我从public void onDrawFrame(GL10 gl) {开始线程我的问题是我将如何实现上述处理程序?我读过http://developer.android.com/reference/android/os/Handler.html,但我仍然不太明白我将如何实施它。有人能帮助我吗?

回答

1

两件事。一个是GLThread永远不会调用Looper.prepare(),因此你不能在该线程中添加/创建一个处理程序。 (应该在主UI线程内)。

二,不需要处理程序。如果你只是想渲染线程中执行代码...

GLSurfaceView mySurface = mMyCustomSurfaceIMadeEarlierWithTheRendererAlreadyAttached; 
Runnable myRunnable = mMyRunnableThatIsSomewhere; 
mySurface.queueEvent(myRunnable); 

了Runnable将渲染线程内之前并条机方法被调用的下一个渲染通道被执行。

相关问题