Cheok Yan Cheng
Cheok Yan Cheng

Reputation: 42760

How to receive Parse push notification only when app is opened, and show it in modal dialog form

I was using https://github.com/ParsePlatform/PushTutorial sample code for a while.

Current example behavior is

  1. Push notification will be received, either the app is opened or closed.
  2. Push notification is in the form of showing icon in status bar with sound.
  3. I cannot find a way to specific notification icon image. Parse is using app icon as notification icon by default. By Android design guideline requires us to have different style and size for notification icon.
  4. When the app is opened, and notification received. Clicking on the notification icon will cause 2nd instance of the same app is launched. That's mean, there will be 2 instances of same app. (Personally, I don't feel this is a correct behavior)

I was wondering

  1. How can I only receive the push notification when app is opened, but not closed?
  2. How can I show it in the form of modal dialog, instance of showing icon in status bar with sound?

Upvotes: 2

Views: 1361

Answers (1)

Srijith Vijayamohan
Srijith Vijayamohan

Reputation: 915

I am not sure about the 4th point, it didn't work that way for me. It opened the same instance for me. I think you are using a different application identifier and have two different application with same name and icon, but different identifier.

Now, for your use case, I think Push notification is not the ideal solution. Depending on what and how frequent you need to show this, you may opt for a repeating pull from the server or if you still want to use Push Notification then subscribe/unsubscribe from a Push Notification Channel when the app is pulled to foreground or background.

ie, when the application is in foreground (onStart() / onResume()), subscribe to a channel:

PushService.subscribe(context, "foregroundPush", YourActivity.class);

and when the application is moving to background (onStop() / onResume() / onDestroy() ), unsubscribe from the same channel:

PushService.unsubscribe(context, "foregroundPush", YourActivity.class);

Whenever you need to send a push notification to the devices with your application in foreground, use the channel 'foregroundPush'

Upvotes: 1

Related Questions