Click on Notification does not work as expected (screencast)

Put your problem here if it does not fit any of the other categories.

Click on Notification does not work as expected (screencast)

Postby mastix » Thu Dec 24, 2009 7:24 am

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...

http://dl.dropbox.com/u/1676562/NotificationIssue.mov

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

Setting the notification:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         // The PendingIntent to launch our activity if the user selects this
  2.  
  3.         // notification
  4.  
  5.         final Intent notificationIntent = new Intent(ManagerFactory
  6.  
  7.                 .getMasterActivity(), MailerActivity.class);
  8.  
  9.         notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
  10.  
  11.                 | Intent.FLAG_ACTIVITY_SINGLE_TOP);
  12.  
  13.         Log.d(TAG, "Set new message to Notification: " + p_message);
  14.  
  15.         notificationIntent
  16.  
  17.                 .putExtra(Constants.NOTIFICATION_EXTRA_KEY, p_message);
  18.  
  19.         Log.d(TAG, "Setting requestCodeToFixNotificationBug: "
  20.  
  21.                 + s_requestCodeToFixNotificationBug);
  22.  
  23.         final PendingIntent contentIntent = PendingIntent.getActivity(
  24.  
  25.                 ManagerFactory.s_service, s_requestCodeToFixNotificationBug++,
  26.  
  27.                 notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  28.  
  29.  
  30.  
  31.         notification.setLatestEventInfo(ManagerFactory.s_service, p_tickerText,
  32.  
  33.                 p_message, contentIntent);
  34.  
  35.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Reacting on the incoming intent:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. /*
  2.  
  3.      * (non-Javadoc)
  4.  
  5.      *
  6.  
  7.      * @see android.app.Activity#onNewIntent(android.content.Intent)
  8.  
  9.      */
  10.  
  11.     @Override
  12.  
  13.     protected final void onNewIntent(final Intent p_intent) {
  14.  
  15.         // when called via notification, get the extras
  16.  
  17.         Log.d(TAG, "Called onNewIntent...");
  18.  
  19.         final Bundle extras = p_intent.getExtras();
  20.  
  21.         Log.d(TAG, "Extra: " + extras);
  22.  
  23.         if (extras != null
  24.  
  25.                 && extras.getString(Constants.NOTIFICATION_EXTRA_KEY) != null
  26.  
  27.                 && !extras.getString(Constants.NOTIFICATION_EXTRA_KEY).trim()
  28.  
  29.                         .equalsIgnoreCase("")) {
  30.  
  31.             Log.d(TAG, "Extra:"
  32.  
  33.                     + extras.getString(Constants.NOTIFICATION_EXTRA_KEY));
  34.  
  35.             this.showLongMessage(extras
  36.  
  37.                     .getString(Constants.NOTIFICATION_EXTRA_KEY));
  38.  
  39.         }
  40.  
  41.     }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4



Would be great if someone was able to help me... :)

Sascha
mastix
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Sep 20, 2009 9:57 am

Top

Postby mastix » Mon Jan 18, 2010 7:14 pm

No ideas? I really thought that this was a simple question... Still guess that it's just a "flag thing"... :)
mastix
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Sep 20, 2009 9:57 am

Postby appforce » Mon Jan 18, 2010 9:53 pm

Hi,

It is possible that extras are not properly attached in the PendingIntent. Try setting some action to the Intent by setAction("dummy").

Android developers
appforce
Experienced Developer
Experienced Developer
 
Posts: 60
Joined: Mon Nov 23, 2009 8:28 pm

Postby mastix » Tue Jan 19, 2010 4:41 pm

I think that wouldn't make a difference... because:

If the app is not active (running in the
background), it will not call onNewIntent() but onCreate(). That's why the message is not displayed. How could
I tell my code to use the old instance instead of creating a new one? This should be handled by these flags, right?

I've already set the launch mode of that activity to "singleTop"!

Thank you very much in advance...

Sascha
mastix
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Sep 20, 2009 9:57 am

Postby appforce » Tue Jan 19, 2010 4:54 pm

Hi,

If that's the case, an easy way to solve is to make an updateUI(Intent intent) method containing what's currently in onNewIntent(). Call it from both onCreate and onNewIntent. Anyway, make sure your extras are delivered by the PendingIntent too, that could also be a problem.

Android developers
appforce
Experienced Developer
Experienced Developer
 
Posts: 60
Joined: Mon Nov 23, 2009 8:28 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 17 guests