0

I have a media player app and I am trying to handle events such as when you receive a phone call. I can get it stopped properly and kill the service. Then I need to switch back to the main activity so when the user gets done with their phone call they can re-select a station to play. The problem I have is when I switch the activity with startActivity(intent) it gets shown in front of the phone dialer--this is not a good user experience. So how can I get my app reset back to the correct activity without it showing in front of another app?

private BroadcastReceiver phoneReceiver = new BroadcastReceiver()
{

    @Override
    public void onReceive(Context context, Intent intent)
    {
        //stop the play service
        Intent stopPlayingService = new Intent(context, Play.class);
        stopService(stopPlayingService);
        //switch back to the main screen
        Intent showMain = new Intent(context, MouseWorldRadioActivity.class);
        showMain.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //showMain.addFlags(Intent.);  not sure whats needed here
        startActivity(showMain);

    }

};
Joeb
  • 95
  • 1
  • 11
  • What programming language and/or SDK are you using? We need to know these details before we can help you. This looks like ActionScript 3 to me, but it could be any number of languages. – CodeMouse92 Mar 16 '12 at 01:46
  • What you want is a way to restart the service after the phone call ends. I'm not familiarized with this particular situation, but I'd guess that you should save the service state before stopping it, and then listen to a "call ended" intent to restart the service again. This way you don't have to ask the user to re-select the station. See http://stackoverflow.com/questions/2477889/intent-to-be-fired-when-a-call-ends for more details. – Telmo Marques Mar 16 '12 at 01:56
  • JasonMC920-Sorry, I did tag this as Android so I just figured it could only be Java related. – Joeb Mar 16 '12 at 20:59

1 Answers1

1

You can try:

 showMain.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 showMain.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
 context.startActivity(showMain);
476rick
  • 2,764
  • 4
  • 29
  • 49
Aashish Bhatnagar
  • 2,595
  • 2
  • 22
  • 37