0

Here I am sending a notification to an app from a class "Gcm". I am passing the intent along with a notification to Group chat Activity. If that Activity is already in active state I want to finish that Group chat activity at the "Gcm".

How do I set whether an activity is in running state or not in another activity

This is my gcm notification code:

  Intent groupChatActFrag = new Intent(getApplicationContext(), GroupChatActivity.class);

            //here messageMO having the details of received message here i am setting eventId from messageMO to eventMO
            // Inorder to passs gropchatActivity

            eventMO.setEventId(messageMO.getEventId());
            groupChatActFrag.putExtra("eventMo", eventMO);

            Log.e("gcm ","eventid"+eventMO);
            groupChatActFrag.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

            SharedPreferences.Editor editor = sharedpreferences.edit();
            editor.putString("MessageMO", gson.toJson(messageMO));
            editor.commit();
            PendingIntent contentIntent = PendingIntent.getActivity(this, 0, groupChatActFrag, PendingIntent.FLAG_UPDATE_CURRENT);


            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_dialog_info).setContentTitle(messageMO.getEventTitle())
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(messageMO.getfromUserName())).setContentText(messageMO.getMessage()).setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

            mBuilder.setContentIntent(contentIntent);

            mBuilder.setAutoCancel(true);
            mNotificationManager.notify((int) (long) messageMO.getEventId(), mBuilder.build());
Afshin Ghazi
  • 2,784
  • 4
  • 23
  • 37
simon peter
  • 39
  • 1
  • 2
  • 11

1 Answers1

0

two ways i would do this: 1] Use Shared preferences and add boolean when starting ending activity. 2] Serialize an object and pass it around (similar but more dependable) with boolean value.

This link may help: Link

You can thus save the state and use this where needed.

These link may also be useful: Detect if activity is running and check if acitivity is running

Community
  • 1
  • 1
Afshin Ghazi
  • 2,784
  • 4
  • 23
  • 37