title: Chat Application - Smack 4.1 Android IntentService - send message
body: <p>I'm creating a chat application in Android, using Smack 4.1. I have implemented an IntentService that creates the connection and log the user in xmpp once the user logs in the application. I am using the following code to start the intentservice from a fragment, that works fine:</p>
  
  <pre><code>chatIntent = new Intent(mContext, ChatService.class);
  chatIntent.setAction(XMPP_ACTION_CONNECT);
  mContext.startService(chatIntent);
  </code></pre>
  
  <p>Then I'm trying to send a message from the fragment. I've tried to use the same code as above </p>
  
  <pre><code>Intent sendmsgIntent = new Intent(mContext, ChatService.class);
  sendmsgIntent.putExtra("msg",messageText);
  sendmsgIntent.putExtra("to",companionLabel.getText().toString());
  sendmsgIntent.setAction(ACTION_SEND_MESSAGE);
  mContext.startService(sendmsgIntent);
  </code></pre>
  
  <p>but when the intent is received in IntentService, the XMPPTCPConnection connection is null and I cannot use the:</p>
  
  <pre><code>connection.sendStanza(message);
  </code></pre>
  
  <p>Why is this null? Does the service start again from the beginning?
  Is this way I'm using to send the second intent wrong?
  Or how could I get the XMPPTCPConnection connection that was created when the first intent was sent?</p>