0

I am using the following code that I want to run after I receive the Push Notification. This piece of code works fine, if my application is in foreground. But in case the application is in background, then after clicking the push notification, the Activity does not called.

Any ideas, what could be the problem. Please let me know.

public void doOnMessageReceive(String message)
    {   
        try {
            JSONObject response = new JSONObject(message);
            String title = response.getString("title");
            Logger.i("title","title :::"+title);

            NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            int icon = R.drawable.ic_launcher;
            CharSequence tickerText = "New notification Pending";
            long time = System.currentTimeMillis();

            Notification notification = new Notification(icon,tickerText,time);            
            notification.flags = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND;
                //| Notification.DEFAULT_VIBRATE |Notification.FLAG_FOREGROUND_SERVICE
                //| Notification.FLAG_HIGH_PRIORITY |Notification.FLAG_ONGOING_EVENT;

            CharSequence contentTitle = "Notifications";
            CharSequence contentText = title;
            Intent notificationIntent = new Intent(this, DetailActivity.class);

            notificationIntent.putExtra(Constants.SELECTED_CATEGORY_KEY, "http://feeds.bbci.co.uk/news/rss.xml");
            notificationIntent.putExtra("guid", title);
            notificationIntent.putExtra(Constants.DISPLAY_ALL_CAT_KEY, true);
            notificationIntent.putExtra(Constants.PARSED_RSS_DATA, RSSDataSingleton.getInstance().getRssDataHM());
        notificationIntent.putExtra(Constants.MAPPED_METADATA_RSS_DATA, RSSDataSingleton.getInstance().getMappedNewsHM());
            PendingIntent contentIntent = PendingIntent.getActivity(this, 99,
                    notificationIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

            notification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent);
            mNotificationManager.notify(1, notification);
        } catch (JSONException e) {
            e.printStackTrace();
        }       
    }
  • Very strange. It should work as expected. verify again, if not then check with the Intent.Flags and PendingIntent.Flags with various combinations. – Rajeev Sahu Aug 28 '13 at 05:41
  • Thanks for your reply. but I have already tried all these combinations for Intent as well as pendingIntent flag. But It does not seems to be useful. – user2706935 Aug 28 '13 at 06:27
  • 1
    After investigating more , It is found that if the app is in foreground or background mode , onReceive() of broadcast receiver is called , and it bahaves as expected. but if the app is stopped then onReceive() does not gets called. In that case it looks for a activity to launch which has packagename.MESSAGE action defined as intent-filter defined in manifest. But I need to send data as well to the launching activity , which does not seems to working as of now. If anyone has any idea how to pass data to a activity which is starting from manifest? Please comment. – user2706935 Aug 28 '13 at 09:08

0 Answers0