I'm implementing GCM. My app has two activities, say A
and B
. I'm using this code to launch B
from the NotificationBar:
long when = System.currentTimeMillis();
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String title = context.getString(R.string.app_name);
Notification notification = new Notification(R.drawable.app_notification_icon, "De Centrale", when);//message
Intent notificationIntent = new Intent(context, B.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); //|Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(context, title, msg, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
NotificationBar opens Activity B
with an Intent, say 'B-notification-intent', then I open Activity A
from B
using Back button, then again I launch B
from A
having a new Intent (say 'B-A-intent'). I use the code below:
intent = new Intent(this, B.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
And then I get New Data in B
(i.e the screen of B
is refreshed).
But if I press the Home button and then I launch the application from Recent app then I get older B
screen with 'B-notification-intent'. Instead, I want the latest Intent, i.e 'B-A-intent'. I'm using this code in B
:
@Override
protected void onCreate(Bundle b)
{
fetchDataFromDB(getIntent());
}
@Override
protected void onNewIntent(Intent intent)
{
fetchDataFromDB(intent);
}
So anybody please help me getting my current screen (intent).