0

I have an audio player which has two main activities. 1.The splash Activity for loading splash page and another for the player.When I press the back button and select my app from the launcher multiple instances of the activities are happening.

Splash Activity-Player-Another Splash Activity-Another player-Another splash activity-Another player A-B-A-B-A-B If I clicked play in all 3 player activities 3 songs will be playing in background.

It is only happening when the back button is pressed. It is not happening when you are pressed the home button.

So as a simple solution for the time being I have disabled the back button.

May I get a solution from anybody.

maddy.999
  • 13
  • 6

3 Answers3

1

You can write in your manifest file

android:launchMode="singleInstance"

In activity tag

<activity
    android:name=".HomeActivity"
    android:launchMode="singleInstance"
</activity>
Nirali
  • 13,571
  • 6
  • 40
  • 53
0

Try this

@Override
public void onBackPressed() {
    Intent ip = new Intent(this, YourMainActivity.class);
    startActivity(ip);
    finish();
    super.onBackPressed();
}
Yash
  • 1,751
  • 13
  • 14
  • Not working.It is calling my player activity(multiple instances) again again while pressing back button & also the music of first player activity is already playing in the background. – maddy.999 Aug 03 '12 at 09:06
  • replace YourMainActivity with the activity which does not contain mediaplayer – Yash Aug 03 '12 at 09:07
  • before player activity only was coming. Now splashactivity(mainactivity) following player activity is coming.Where the song plays in background and player activity is a new one. – maddy.999 Aug 03 '12 at 09:31
0

Have a look at http://developer.android.com/guide/topics/manifest/activity-element.html#lmode

and http://developer.android.com/guide/components/tasks-and-back-stack.html

If you can show some code, it would be easier to figure out exact issue.

Sangharsh
  • 2,999
  • 2
  • 15
  • 27