0

I am making an android app which plays mp3 files. I am launching the mp3 playing activity from within another activity using intent:

Intent intent=new Intent(ListViewA.this,mp3player.class);
                intent.putExtra("feed",gh);
                i.setFlags(0);
                i.setPackage(null);
                //intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                startActivity(intent);

Now when the user selects another song from a list, I want to close the previous instance of the mp3player activity and start a new one using the intent code (above). How do I go about doing that? Thanks.

vergil corleone
  • 1,091
  • 3
  • 16
  • 34

2 Answers2

0

Instead of startActivity use startActivityForResult(intent, PLAY_SONG) then you can call finishActivity(PLAY_SONG) where PLAY_SONG is a constant number.

class member

private static final int PLAY_SONG  

And then

finishActivity(PLAY_SONG);
Intent intent=new Intent(ListViewA.this,mp3player.class);
intent.putExtra("feed",gh);
i.setFlags(0);
i.setPackage(null);
startActivityForResult(intent, PLAY_SONG)  
Hoan Nguyen
  • 18,033
  • 3
  • 50
  • 54
0

Hey its very simple Instead of calling Intent from Mp3Playeractivity call finish() when you are pressing the back button by implementing

@Override
public void onBackPressed(){
finish();
}

which will cause close your MpeplayerActivity

Abhijit Chakra
  • 3,201
  • 37
  • 66