Execute method when user leaves and then starts application
<p>I have a question about the android lifecycle. This is my <strong>onCreate</strong> method of my main application: </p>

<pre><code>@Override
public void onCreate(Bundle b) {
    super.onCreate(b);
    decode = new Decode(this);

    adjustToDimensions();
    setLoadingScreen("Zorgdossier wordt geladen...");
    initReceiver();
    startCommunicationWithServer();
}
</code></pre>

<p>I set the screen to a loading screen, initialize a broadcastReceiver and send a message to the server. </p>

<p>Now, when I press the home button and start my application again I always want to start this activity so I've added </p>

<pre><code>android:clearTaskOnLaunch="true"
</code></pre>

<p>To the manifest.</p>

<p>But now I want the <strong>startCommunicationWithServer</strong>() to be executed when the user starts the application again. This method sends a message to the server, and the server on the other hand sends a message that I receive in the receiver. 
With this message I decide which screen to show.</p>

<p>I've tried to put it in the <strong>onRestart</strong> method:</p>

<pre><code>    @Override
protected void onRestart() {
    Log.d("MainActivity", "activity restarted");
    startCommunicationWithServer();
    super.onRestart();
}
</code></pre>

<p>But this activity is shown multiple times troughout the application, so the onRestart method is executed each time. But I only need the <strong>startCommunicationWithServer</strong>() to be executed at the start of the application.</p>

<p>So long story short, how can I call the <strong>startCommunicationWithServer</strong>() method when the user exits and subsequently starts my application? </p>
