1. Are you ready for the Galaxy S20? Here is everything we know so far!

Click on Notification does not work as expected... (see screencast!):(

Discussion in 'Android Development' started by mastix, Dec 24, 2009.

  1. mastix

    mastix Lurker
    Thread Starter

    Hi guys,

    first of all - Merry Christmas!!! :)

    I have a strange problem here and spent too many hours figuring out what the problem might be. I definitely need your help here now... I'm pretty sure this is very easy to fix... if you know how... :)

    I develop a little free app for German O2 customers so that they can send their 50 free Web-SMS directly from their Android phone and not only via web interface like O2 wants them to. These SMS are sent in the background using a service. This service generates notifications (e.g. Message sent successfully, Login successful/failed,...)

    When I click on that notification the app should open and then display the notification message. This works pretty fine as long as the app is visible (foreground/active). When putting the app into the background it's getting launched as well, but it doesn't display the message... then, when I hold down the HOME-Key and select the app... the message gets displayed.

    See the following video... to show you what I mean...


    I'm pretty sure it has something to do with the Fflags for my intent, so here's my code:

    Setting the notification:

    Code (Text):
    2.     // The PendingIntent to launch our activity if the user selects this
    3.     // notification
    4.     final Intent notificationIntent = new Intent(ManagerFactory
    5.         .getMasterActivity(), MailerActivity.class);
    6.     notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
    7.         | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    8.     Log.d(TAG, "Set new message to Notification: " + p_message);
    9.     notificationIntent
    10.         .putExtra(Constants.NOTIFICATION_EXTRA_KEY, p_message);
    11.     Log.d(TAG, "Setting requestCodeToFixNotificationBug: "
    12.         + s_requestCodeToFixNotificationBug);
    13.     final PendingIntent contentIntent = PendingIntent.getActivity(
    14.         ManagerFactory.s_service, s_requestCodeToFixNotificationBug++,
    15.         notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    17.     notification.setLatestEventInfo(ManagerFactory.s_service, p_tickerText,
    18.         p_message, contentIntent);
    Reacting on the incoming intent:

    Code (Text):
    2. /*
    3.      * (non-Javadoc)
    4.      *
    5.      * @see android.app.Activity#onNewIntent(android.content.Intent)
    6.      */
    7.     @Override
    8.     protected final void onNewIntent(final Intent p_intent) {
    9.     // when called via notification, get the extras
    10.     Log.d(TAG, "Called onNewIntent...");
    11.     final Bundle extras = p_intent.getExtras();
    12.     Log.d(TAG, "Extra: " + extras);
    13.     if (extras != null
    14.         && extras.getString(Constants.NOTIFICATION_EXTRA_KEY) != null
    15.         && !extras.getString(Constants.NOTIFICATION_EXTRA_KEY).trim()
    16.             .equalsIgnoreCase("")) {
    17.         Log.d(TAG, "Extra:"
    18.             + extras.getString(Constants.NOTIFICATION_EXTRA_KEY));
    19.         this.showLongMessage(extras
    20.             .getString(Constants.NOTIFICATION_EXTRA_KEY));
    21.     }
    22.     }
    Would be great if someone was able to help me... :)


    1. Download the Forums for Android™ app!



Share This Page