Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating Activity on receiving through Service
    primarykey
    data
    text
    <p>I have an application which uses an <code>IntentService</code> to handle incoming Google Cloud Messaging messages. Currently I am creating a notification whenever I get a message through the <code>onHandleIntent()</code> function. The notification opens up a specific activity and then does some calculations and updates the UI. I'm trying to make my implementation such that if I am already on the Activity that the notification will open, then the Service should be able to update the UI without having to send a notification. I am assuming I can use a broadcast receiver to do this, but I am not sure how to implement it such that it should update the Activity only if that Activity is running else it should post a notification.</p> <p>I am not sure how to do the following:</p> <ol> <li><p>Check if the specific Activity is already running.</p></li> <li><p>If the Activity is already running then perform the required Calculations and UI updates without having to call <code>startActivity()</code></p></li> </ol> <p><strong>EDIT:</strong> I have made some changes to my code but I am not see the logcat messages that I have added in the onReceive() method.</p> <p>I've added the following code to the onHandle() function in my IntentService class:</p> <pre><code>Intent in = new Intent("com.example.gcm.DataActivity"); sendBroadcast(in); </code></pre> <p>"com.example.gcm" is my package name and DataActivity is the name of the Activity.</p> <p>I've added the following code to my Activity:</p> <pre><code>@Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); Log.d(TAG, "start"); receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Log.d(TAG, "notif received"); } }; } @Override protected void onStop() { // TODO Auto-generated method stub super.onStop(); unregisterReceiver(receiver); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload