Skip to content Skip to sidebar Skip to footer

Parse Push Notification - Alert Dialog Not Appearing When App Is Closed

I'm new to Parse, and have made an app that receives push notifications. I have a json payload that I am sending to the app which contains a URL. When the push notification is rece

Solution 1:

I had the same issue with Parse Notifications. Here's how I got mine to work.

  1. find out the current activity, see https://stackoverflow.com/a/13994622/2383911
  2. if current activity == null, that means app is backgrounded
  3. open the last activity
  4. wait 2 seconds (to be safe) to pass the intent back to the onReceive function.
  5. from there your alertdialog function should work.

    public void onReceive(final Context context, final Intent intent) {

    currentActivity = ((Launch) context.getApplicationContext()).getCurrentActivity();

    if (currentActivity == null) {
            IntentnotificationIntent=newIntent(context, Login.class);
            notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            notificationIntent.setAction(Intent.ACTION_MAIN);
            finalHandlerh=newHandler();
            finalintdelay=1000; //milliseconds
    
            h.postDelayed(newRunnable() {
                publicvoidrun() {
                    onReceive(context, intent);
    
                }
            }, delay);
        }
    

Edit: After further testing this real hacky solution- I found out that if you have multiple notifications pending, this method will create alertdialogs for every single pending notification and put them on top of each other... if anyone can figure out how to only make the chosen notification show up, I'd be forever grateful! more info here- https://stackoverflow.com/questions/26020523/displaying-a-parse-com-push-notification-with-alert-and-title-keys-as-an-ale

Post a Comment for "Parse Push Notification - Alert Dialog Not Appearing When App Is Closed"