Call activity method from intent service
<p>There are many questions on how to invoke an activity method from a service using a broadcast receiver or an interface. But the examples often differs from my case.</p>

<p>I have an activity that sends a registration request to a server. This server sends it's requested answer via <strong>google cloud messaging (GCM)</strong>. To receive the answer I use a <strong>service</strong>.</p>

<p><strong>My manifest</strong>:</p>

<pre><code>&lt;!-- receiver to handle GCM messages --&gt;
&lt;receiver
   android:name="com.google.android.gcm.GCMBroadcastReceiver"
   android:permission="com.google.android.c2dm.permission.SEND" &gt;
   &lt;intent-filter&gt;
      &lt;!-- Receives the actual messages. --&gt;
      &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
      &lt;action android:name="com.google.android.c2dm.intent.REGISTRATION" /&gt;
      &lt;category android:name="com.example.myapp" /&gt;
   &lt;/intent-filter&gt;
&lt;/receiver&gt;
&lt;service android:name=".GCMIntentService" /&gt;
</code></pre>

<p>In my activity, I have a switch. If the user checks the switch the registration process starts and I disable the switch, so the user could not change the switch state during the registration process. After a certain time (about 5 Min) the server sends the answer.</p>

<p>Depending on the answer, I want to set the state of the switch (checked or unchecked) and enable the switch again.  </p>

<p>My question is now, how can I achieve this behaviour? How can I invoke a method in the activity?  </p>

<p>The next problem is that the user probably closes the app because the request needs some time. How can I achieve, that the method will be executed even if the activity was closed?</p>

<p>Regarding the questions, I have read in the forum I would use a <strong>LocalBroadcastReceiver</strong>. Would this receiver work, if the app was closed? Or if it is closed, would it bring the activity to the front (I don't want this)?</p>