Why is this app running slow?
<p>Why does this app stop answering then I press play? It sometimes show a "the application is not responding" but it works if I wait.</p>

<p>It works nice on my emulator, but not on my phone (or any other phone I tried).</p>

<p>All it does is streaming sound.</p>

<pre><code>package comunicera.se;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.ListActivity;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ProgressBar;
import android.widget.TextView;

public class Godnattsaga extends ListActivity {
/** Called when the activity is first created. */


ListView list;
TextView spelandesSagqa;
//private ProgressDialog mProgressDialog;
 ProgressBar myProgressBar;
 int myProgress = 0;
 MediaPlayer mp = new MediaPlayer();
 String BASEURL = "http://godnattsaga.nu/sagor";
 public static long glCurrentSaga = 0;
 public static String giCode = null;
 int giAntalSagor = 0;
 int possWhenPaused = 0;
 ProgressBar myBufferProgressBar;
 TextView buffrarText;
 int progress;


public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    try
    {

        new Thread(buffer).start();
        String lsSagor = getFileFromUrl(BASEURL+"/gratisSagor.txt");

        final String[] laList = lsSagor.split("~");

        giAntalSagor = laList.length;

        //String saga = laList[0].replaceAll("#", "\n");
        String[] laSaga = laList[0].split("#");

        final String[] guiLaList = new String[giAntalSagor];
        for (int i = 0; i &lt; giAntalSagor; i++)
        {
            guiLaList[i] = laList[i].replaceAll("#", "\n");
        }

        changeSpelandesSaga(laSaga[0]);

        setList (guiLaList);


        ListView list = getListView();
        list.setTextFilterEnabled(true);

        list.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                    int position, long id) {
                        String liCode = kop(id);

                        glCurrentSaga = id;
                        String[] laSaga = laList[(int) glCurrentSaga].split("#");
                        changeSpelandesSaga(laSaga[0]);
                    }
        });

        final Button button = (Button) findViewById(R.id.SpelaPause);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                selectDownloadOrPLay(laList);
            }
        });
        glCurrentSaga = 0;
        changeSpelandesSaga(laSaga[0]);



    }
    catch (Exception e) 
    {
        changeSpelandesSaga("Check your connection, are you in flightmode?");

    }
}

public void selectDownloadOrPLay(String[] laList) {
    String[] laSaga = laList[(int) glCurrentSaga].split("#");



    String url =  BASEURL+"/gratis/"+laSaga[0].replaceAll(" ", "_")+".mp3";

    if (mp.isPlaying())
    {
        mp.pause();
        possWhenPaused=mp.getCurrentPosition();
    }
    else if (possWhenPaused != 0)
    {
        mp.start();
    }
    else
    {       
        startSaga (url);
    }

}

private String kop(long id) 
{
    mp.pause();

    return "gratis";
}
public void setList (String[] laList)
{
    /*
     *
      final String[] lAList = new String[3];

    lAList[0] = "Saga 1 \n";
    lAList[1] = "Saga 2 \n";        
    lAList[2] = "Saga 3";

    setList (lAList);

     * 
     */


    setContentView(R.layout.main);
    ArrayAdapter&lt;String&gt; appointmentList = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, laList);
    list=(ListView)findViewById(android.R.id.list);
    list.setAdapter(appointmentList);
}
public void changeSpelandesSaga(String sagaRubrik)
{
    possWhenPaused = 0;

    TextView t = new TextView(this); 
    t=(TextView)findViewById(R.id.spelandesSaga); 
    t.setText(Html.fromHtml("&lt;b&gt;"+sagaRubrik+"&lt;/b&gt;"));
}


private void startSaga(String url) 
{
    try {
        mp.reset();
        mp.setDataSource(url);
        mp.prepare();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


    mp.start();

    myProgressBar=(ProgressBar)findViewById(R.id.mProgressDialog);

    new Thread(myThread).start();
}

private Runnable myThread = new Runnable(){
    @Override
    public void run() {
        // TODO Auto-generated method stub
        while (myProgress&lt;100){
            try{
                myHandle.sendMessage(myHandle.obtainMessage());
                Thread.sleep(1000);
            }
            catch(Throwable t){
            }
        }
    }

    Handler myHandle = new Handler(){

        double poss = 0.0;
        double sagaleng = 0.0;

        @Override
        public void handleMessage(Message msg) {
            //  TODO Auto-generated method stub

            poss = mp.getCurrentPosition();
            sagaleng = mp.getDuration();

            progress = (int) ((int)poss / sagaleng * 100);

            myProgress = progress;
            myProgressBar.setProgress(progress);

        }
    };

};
public static String getFileFromUrl(String url) 
{
    InputStream content = null;
    try 
    {
        HttpGet httpGet = new HttpGet(url);
        HttpClient httpclient = new DefaultHttpClient();
        // Execute HTTP Get Request
        HttpResponse response = httpclient.execute(httpGet);
        content = response.getEntity().getContent();
    }
    catch (Exception e) 
    {
        showNoConnection ();
        return null;
    }
    BufferedReader rd = new BufferedReader(new InputStreamReader(content), 4096);
    String line;
    StringBuilder sb =  new StringBuilder();
    try {
        while ((line = rd.readLine()) != null) {
                sb.append(line);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        rd.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return sb.toString();


}
public boolean isOnline() {
     ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

     boolean connected = cm.getActiveNetworkInfo().isConnectedOrConnecting();

     return connected;

}

private static void showNoConnection() 
{

}
private Runnable buffer = new Runnable(){
    @Override
    public void run() {
        // TODO Auto-generated method stub
        while (myProgress&lt;100){
            try{
                myHandle.sendMessage(myHandle.obtainMessage());
                Thread.sleep(1000);
            }
            catch(Throwable t)
            {
            }
        }
    }
        Handler myHandle = new Handler(){


        @Override
        public void handleMessage(Message msg) {
            //  TODO Auto-generated method stub
            //SpelaPause.setImageURI("pauseicon");
            myBufferProgressBar = (ProgressBar)findViewById(R.id.mBuffrar);
            TextView bufferText = (TextView)findViewById(R.id.buffrarText);

            if (mp.isPlaying() &amp;&amp; progress == 0)
            {
                myBufferProgressBar.setVisibility(View.VISIBLE);
                bufferText.setVisibility(View.VISIBLE);
            }
            else
            {
                myBufferProgressBar.setVisibility(View.INVISIBLE);
                bufferText.setVisibility(View.INVISIBLE);
            }




        }
    };

};
</code></pre>

<p>}</p>
