How to make a single instance application in android?
<p>I'm a newbie in android and  I have a question about that.</p>

<p>How can I make a single application in android?
 I googled it and I got a method to resolve it is to set launchMode to singleTask or singleInstance, of course I tried but I didn't get a expected resolve.</p>

<p>Actually I had a MP3 player app, when run it then:</p>

<p>Press Home button->press and hold home button-> select my app-> it resumed OK.</p>

<p>But when it is launched then:</p>

<p>Press Back button->press and hold home button-> select my app-> it resumed not OK. I mean android created a new instance of my app, and you know, 2 app run together, but I don't want that. </p>

<p>I tried setting launch mode to singleTask. It works OK in the first activity ( which I set to singleTask) but when I press a button in screen to refer to new activity ( that I dont set to sigleTask) and it didn't work OK.</p>

<p>My app has many activities so i think setting launch mode to singleTask or singleInstane is not good totally.</p>

<p>Looking forward to your answers.</p>

<p>Thank you.
@@: I'm very sorry if there any english grammar mistake ( I'm not good at English).</p>

<p>UPDATE:</p>

<p>I have fixd that problem, but now I doubt about my emulator.
As you mentioned before, press back button will destroy app, ( call finish() method), so all enviroment that my app holds will be released. But when I pressd back button, my app probably still runs because I still hear the song being played.?</p>

<p>My code:</p>

<pre><code>public class MainActivity extends Activity {

MediaPlayer mp;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mp = new MediaPlayer();
    playSong("sdcard/Music/lung ta lung tung.MP3");
}


public void playSong(String str)
{
    try {
        mp.setDataSource(str);
        mp.prepareAsync();
        mp.setOnPreparedListener(new OnPreparedListener() {

            public void onPrepared(MediaPlayer arg0) {

                mp.start();
            }
        });
    } catch (IllegalArgumentException e) {

        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
</code></pre>
