tags:

views:

25

answers:

1

I have Acvtivity that creates view and mediaplayer. I want to use OnCompletion event to make that view clickable. But it throws exception, I don't know why. Probably, mediaplayer runs in another thread and cannot access elements from main ui thread? Thank you for any information

+1  A: 

Use Activity.runOnUiThread() to make sure your code is running in the correct thread.

    //assuming this code is within an Activity class, you can
    //access this function directly. Otherwise you must
    //have a reference to an Activity object
    this.runOnUiThread(new Runnable() 
    {
        public void run()
        {
            //perform UI-thread only tasks
        }
    });
Aaron C