Is this properly using a runnable?

by Jonathan » Fri, 26 Feb 2010 03:14:19 GMT


Sponsored Links
 I am basing an audioplayer off an old tutorial, and I am seeing some
major lag in my UI, which is making me think that the threading is not
being handled properly. It is structured as such:

    public void startStreaming() throws IOException {
        final String mediaUrl =
currentTrackData.get("play_url").toString();
                Runnable r = new Runnable() {
                public void run() {
                    try {
                                downloadAudioIncrement(mediaUrl);
                    } catch (IOException e) {
                        Log.e(getClass().getName(), "Unable to initialize the
MediaPlayer for fileUrl=" + mediaUrl, e);
                        return;
                    }
                }
            };
            new Thread(r).start();
    }


    public void downloadAudioIncrement(String mediaUrl) throws
IOException {
        //do audio downloading and buffering in here in here
        //there is not threading logic in here at all
    }


I've ommitted the specific downloading code for brevity. Does calling
a function from a runnable mean that the logic will be run off the
main UI thread?

I can provide more specifics if need be. Thanks

--



Is this properly using a runnable?

by Gaunt Face » Sat, 27 Feb 2010 05:31:53 GMT


 are you updating the UI at all in the thread? From that code,
everything should be done in the background and therefore leave the
main UI happy, if however you are updating the UI, either the update
is taking to long outside of the thread or your updating it so often
that it is locking up the UI.

However I've not performed any task like this so couldn't say if there
were any specific case I might be missing.

Cheers,
Matt




--


Sponsored Links


Other Threads

1. Barcode Library?

Is there a barcode library that will let my app scan barcodes?

Pointer please?

Thanks!

--~--~---------~--~----~------------~-------~--~----~

2. how to open another screen

hi all,
I am using three radiobuttons for three different applications. When i
select one particular radiobutton, it should open another screen to
show that particular application. Similarly for all the three
radiobuttons. Can anybody tel me how can i do this..

thanks in advance....

--~--~---------~--~----~------------~-------~--~----~

3. How to call callActivityOnRestoreInstanceState of Instrumentation

4. Supported audio/video/image format

5. Tough Problem

6. OpenGL ES 1.1 - Point Sprites

7. LocationManager causes application to crash