Search code examples
androidmultithreadingsd-card

how to do thread operations in android


Anyone give example program which explains android Threads in a simpler way. For example, i want to list out the songs in a sd card in thread at the time of launch

i am using the following code to get the number of songs in sd card of an android device. From this i want to list out the songs in thread

private void init_phone_sd_card() 
    {   
        System.gc();
        final String[] proj = { MediaStore.Audio.Media._ID,MediaStore.Audio.Media.DATA,MediaStore.Audio.Media.DISPLAY_NAME,MediaStore.Audio.Media.SIZE };
        Log.e("media",""+proj);

        musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,proj, null, null, null);
        Log.e("media1",""+musiccursor);

        count = musiccursor.getCount();
        Log.e("media2",""+count);

how to do this......

Thx


Solution

  • Just put your code to AsyncTask's doInBackground() method. Task also should show ProgressDialog in order to tell user that some useful work is running. See this article.