0

I'm making a chat app with different ways to chat (group chat, chat roulette, etc.) For some of these different Activities, I need them to call a function which is specific to the activity it lives in whenever the user decides to leave ( such as disconnectFromGroupChat() or disconnectFromChatRoulette() ).

For example, I currently call these functions when the user clicks my "Leave" button or back button on the phone.

But I realized I don't handle this for notification clicks that take me to a new activity.

How do I handle this?

I found this answer, but in all honesty I don't quite understand it so I'm not sure if that's the right approach to take.

Community
  • 1
  • 1
Kacy
  • 3,330
  • 4
  • 29
  • 57
  • You can make dynamic BroadcastReceiver class, and pass reference of your activity and you can trigger activity methods "onReceive" inside BroadCastReceiver class. Also don't forget to register, unregister receiver onCreate(), onDestroy() or onPause(). – Djordje Tankosic Mar 09 '15 at 17:46
  • @DjordjeTankosic That makes sense, and luckily I already keep a static reference to the current activity, but how would I trigger broadcasting the message when the notification is clicked? – Kacy Mar 09 '15 at 17:50
  • I have a button in my notification, I'll modify my code, and I'll post it later. – Djordje Tankosic Mar 09 '15 at 17:59
  • Unfortunately, adding a button to each different kind of notification doesn't really make sense for my app. – Kacy Mar 09 '15 at 18:04

0 Answers0