1

I've got 2 classes GLLayer and GLCamTest. I'm attempting to run a method located in 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;
    }

I'm looking to run in on a thread from GLLayer but from what I understand I need a Handler..

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

}

I'm starting the Thread from within public void onDrawFrame(GL10 gl) { my question is how would I implement said handler? I've read http://developer.android.com/reference/android/os/Handler.html but I still don't really understand how I'd implement it. could someone help me out?

1 Answer 1

1
+50

Two things. One is that the GLThread never called Looper.prepare() therefore you can't add/create a handler inside that thread. (Should be inside the main UI thread).

Two, a handler isn't needed. If you just want to execute code inside the render thread...

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

The runnable will be executed inside your render thread before the drawFrame method gets called on the next rendering pass.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.