我在Android中使用推送通知。当我收到一个推送通知并点击它时,它会根据我的需要启动一项活动,但如果此活动已打开,则此活动将保留旧数据。当点击通知时更新活动
AndroidManifest.xml中
<activity
android:name=".Detail"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_detail"
android:launchMode="singleTop"
android:parentActivityName=".Home"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="ma.via.marocagenda.Home" />
</activity>
GCMIntentService.java
public class GCMIntentService extends GCMBaseIntentService {
...
private static void generateNotification(Context context, String message) {
//int icon = R.drawable.abc_ic_go;
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, Detail.class);
// put extra for details
notificationIntent.putExtra("id", VAL_TAG_ID);
notificationIntent.putExtra("titre", VAL_TAG_TITRE);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
//PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}
什么可以是错误的?
你的问题是什么? – suitianshi 2014-08-30 13:28:32
如果“详细信息”活动已启动,并且点击通知没有任何事情发生,活动不会用新数据更新 – leonidas79 2014-08-30 13:29:31
也覆盖onNewIntent? – Deucalion 2014-08-30 13:42:15