@Override
  protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    Bundle extras = intent.getExtras();
    if (extras != null && extras.getBoolean("GoToChat", false)) {
      LinphoneService.instance().removeMessageNotification();
      String sipUri = extras.getString("ChatContactSipUri");
      displayChat(sipUri);
    } else if (extras != null && extras.getBoolean("Notification", false)) {
      if (LinphoneManager.getLc().getCallsNb() > 0) {
        LinphoneCall call = LinphoneManager.getLc().getCalls()[0];
        if (call.getCurrentParamsCopy().getVideoEnabled()) {
          startVideoActivity(call);
        } else {
          startIncallActivity(call);
        }
      }
    } else {
      if (dialerFragment != null) {
        if (extras != null && extras.containsKey("SipUriOrNumber")) {
          if (getResources().getBoolean(R.bool.automatically_start_intercepted_outgoing_gsm_call)) {
            ((DialerFragment) dialerFragment).newOutgoingCall(extras.getString("SipUriOrNumber"));
          } else {
            ((DialerFragment) dialerFragment)
                .displayTextInAddressBar(extras.getString("SipUriOrNumber"));
          }
        } else {
          ((DialerFragment) dialerFragment).newOutgoingCall(intent);
        }
      }
      if (LinphoneManager.getLc().getCalls().length > 0) {
        LinphoneCall calls[] = LinphoneManager.getLc().getCalls();
        if (calls.length > 0) {
          LinphoneCall call = calls[0];

          if (call != null && call.getState() != LinphoneCall.State.IncomingReceived) {
            if (call.getCurrentParamsCopy().getVideoEnabled()) {
              startVideoActivity(call);
            } else {
              startIncallActivity(call);
            }
          }
        }

        // If a call is ringing, start incomingcallactivity
        Collection<LinphoneCall.State> incoming = new ArrayList<LinphoneCall.State>();
        incoming.add(LinphoneCall.State.IncomingReceived);
        if (LinphoneUtils.getCallsInState(LinphoneManager.getLc(), incoming).size() > 0) {
          if (InCallActivity.isInstanciated()) {
            InCallActivity.instance().startIncomingCallActivity();
          } else {
            startActivity(new Intent(this, IncomingCallActivity.class));
          }
        }
      }
    }
  }
  public void resetClassicMenuLayoutAndGoBackToCallIfStillRunning() {
    if (dialerFragment != null) {
      ((DialerFragment) dialerFragment).resetLayout(false);
    }

    if (LinphoneManager.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0) {
      LinphoneCall call = LinphoneManager.getLc().getCalls()[0];
      if (call.getState() == LinphoneCall.State.IncomingReceived) {
        startActivity(new Intent(LinphoneActivity.this, IncomingCallActivity.class));
      } else if (call.getCurrentParamsCopy().getVideoEnabled()) {
        startVideoActivity(call);
      } else {
        startIncallActivity(call);
      }
    }
  }
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Object selectedItem = autoCompleteAdapter.getItem(position);
    if (selectedItem != null) {

      // Well that a little bit too direct it should be more a listener
      // But not sure how fragments will behaves on restore for now
      Activity superAct = getActivity();
      if (superAct instanceof SipHome) {
        Fragment frag = ((SipHome) superAct).getCurrentFragment();
        if (frag != null && frag instanceof DialerFragment) {
          ((DialerFragment) frag)
              .setTextFieldValue(
                  autoCompleteAdapter.getFilter().convertResultToString(selectedItem));
        }
      }
    }
  }
 private void initInCallMenuLayout(boolean callTransfer) {
   selectMenu(FragmentsAvailable.DIALER);
   if (dialerFragment != null) {
     ((DialerFragment) dialerFragment).resetLayout(callTransfer);
   }
 }