New: XDA launches forum for app developers. Discuss coding, tools, marketing, and more.
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
mastixmc
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 5
Join Date: Jun 2009
Location: Stuttgart
Default Click on Notification does not work as expected... (see screencast!):(

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:

Code:
	// The PendingIntent to launch our activity if the user selects this
	// notification
	final Intent notificationIntent = new Intent(ManagerFactory
		.getMasterActivity(), MailerActivity.class);
	notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
		| Intent.FLAG_ACTIVITY_SINGLE_TOP);
	Log.d(TAG, "Set new message to Notification: " + p_message);
	notificationIntent
		.putExtra(Constants.NOTIFICATION_EXTRA_KEY, p_message);
	Log.d(TAG, "Setting requestCodeToFixNotificationBug: "
		+ s_requestCodeToFixNotificationBug);
	final PendingIntent contentIntent = PendingIntent.getActivity(
		ManagerFactory.s_service, s_requestCodeToFixNotificationBug++,
		notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

	notification.setLatestEventInfo(ManagerFactory.s_service, p_tickerText,
		p_message, contentIntent);
Reacting on the incoming intent:

Code:
/*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onNewIntent(android.content.Intent)
     */
    @Override
    protected final void onNewIntent(final Intent p_intent) {
	// when called via notification, get the extras
	Log.d(TAG, "Called onNewIntent...");
	final Bundle extras = p_intent.getExtras();
	Log.d(TAG, "Extra: " + extras);
	if (extras != null
		&& extras.getString(Constants.NOTIFICATION_EXTRA_KEY) != null
		&& !extras.getString(Constants.NOTIFICATION_EXTRA_KEY).trim()
			.equalsIgnoreCase("")) {
	    Log.d(TAG, "Extra:"
		    + extras.getString(Constants.NOTIFICATION_EXTRA_KEY));
	    this.showLongMessage(extras
		    .getString(Constants.NOTIFICATION_EXTRA_KEY));
	}
    }
Would be great if someone was able to help me...

Sascha
 
zer0day
Old
#2  
Senior Member
Thanks Meter 8
Posts: 221
Join Date: Oct 2007
Does onNewIntent get called? If it does, try stepping through the code with a debugger. Also try setting a unique value to the Intent's data field like System.currentTimeMillis().

Doing this fixed a similar issue for me.
Blog | AndChat - IRC for Android | Remember: Unused RAM is wasted RAM
Tags
airmail, android, flags, intent, notification