我正在实施GCM . 我的应用程序有两个活动,比如 A 和 B . 我正在使用此代码从NotificationBar启动 B :
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用Intent打开Activity B ,比如'B-notification-intent',然后我使用Back按钮从 B 打开Activity A ,然后我再次从具有新Intent(例如'B-A-intent')的 A 启动 B . 我使用下面的代码:
intent = new Intent(this, B.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
然后我在 B 中获得了新数据(即刷新了 B 的屏幕) . 但是,如果我按下主页按钮,然后我从最近的应用程序启动应用程序,那么我会使用'B-notification-intent'获得更长的 B 屏幕 . 相反,我想要最新的意图,即'B-A-intent' . 我在 B 中使用此代码:
@Override
protected void onCreate(Bundle b)
{
fetchDataFromDB(getIntent());
}
@Override
protected void onNewIntent(Intent intent)
{
fetchDataFromDB(intent);
}
所以任何人请帮助我获取当前的屏幕(意图) .