title: Android: Starting new Activity from Application Class
body: <p>I have an android app that plays audio from the application class. I have a PhoneStateListener in my application class that pauses the audio when there is a phone call. </p>
  
  <p>I want to start a particular activity when the call ends, but I am unable to. here is my code:</p>
  
  <pre><code>public void getPhoneState(){
  
  TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
  PhoneStateListener phoneStateListener = new PhoneStateListener() {
      @Override
      public void onCallStateChanged(int state, String incomingNumber) {
  
          if (state == TelephonyManager.CALL_STATE_RINGING) {
              if(audio.isPlaying())
                 audioPlayer.pause();
  
          } 
              else if(state == TelephonyManager.CALL_STATE_IDLE) {
  
                  audio.start();
                  Intent missintent= new Intent(context,AudioActivity.class);
                  missintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  startActivity(missintent);
  
  
          } 
              else if(state == TelephonyManager.CALL_STATE_OFFHOOK) {
  
              if(audio.isPlaying())
              audioPlayer.pause();
  
          }
          super.onCallStateChanged(state, incomingNumber);
  
  
      }
  };
  
  if(mgr != null) {
      mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
  }
  }
  
  public boolean handleAudio(String source, int id) {
  
  phoneState();
  //Code for Playing Audio
  .....
  .....
  }
  </code></pre>
  
  <p>I would appreciate it if someone could show me how to start the activity in the correct manner.</p>
  
  <p>Thanks!</p>