`
byandby
  • 浏览: 1688267 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

发通知 PendingIntent 中Intent 内容没有更新

阅读更多
<activity android:name="SkyfileActivity" 
	 	 android:launchMode="singleTask" />
   当我们把Activity 启动模式设置为 singleTask 之后 当我们下次 再去 用Intent 启动 这个 Activity 的时候 就不会去调用 onCreate方法 而是去调用onNewIntent()方法 然后把Intent中的数据传给它 , 前几天遇到的问题是  当我 发一个通知给状态栏  然后点击这个通知  自然会执行 PendingIntent 里边的Intent。  但是   在Activity那边的 onNewIntent()方法里边 得到的数据  不是最新的 也就是说 是 第一次的 以后 不管我怎么点通知 它都 是 第一次点击通知得到的数据,当以后再点击通知的时候其实 数据已经变了 但是 onNewIntent()方法总是得不到最新的数据,   无语了很久,  去 农民伯伯翻译组 发问得解    需要给 PendingIntent 加一个 FLAG

PendingIntent contentIntentBegin = PendingIntent.getActivity(
					notificationContext, 0, inStart, PendingIntent.FLAG_UPDATE_CURRENT);


   最后一个参数就是 FLAG,这个FLAG 的 意思就是:如果系统中已存在该PendingIntent对象,那么系统将保留该PendingIntent对象,但是会使用新的Intent来更新之前PendingIntent中的Intent对象数据,例如更新Intent中的Extras。这个非常有用,例如之前提到的,我们需要在每次更新之后更新Intent中的Extras数据,达到在不同时机传递给MainActivity不同的参数,实现不同的效果。

   就是 Intent里边的数据没更新而已, 很2个问题 搞了很久 才发现原来加个FLAG 就行了,有点伤不起了。!!

  代码片段
	public void showNotiMessageBegin(String message, int requestCode,
			String itemid) {
		notification = new Notification(R.drawable.skyfile_upload_noti,
				message, System.currentTimeMillis());
		if (requestCode == 1 && notification.contentIntent == null) {
			int index = itemid.lastIndexOf("/");
			final String backPath1 = itemid
					.substring(0, index == 0 ? 1 : index);
			           
			Intent inStart = new Intent(notificationContext, SkyfileActivity.class);
			inStart.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			inStart.setData(Uri.parse(MetaDataView.class.getName()));
			inStart.putExtra(MetaDataView.BUNDLE_PATH, backPath1);
			PendingIntent contentIntentBegin = PendingIntent.getActivity(
					notificationContext, 0, inStart, PendingIntent.FLAG_UPDATE_CURRENT);
			notification.contentIntent = contentIntentBegin;
			notification.flags |= Notification.FLAG_AUTO_CANCEL;
			notification.setLatestEventInfo(notificationContext,
					UPLOATTITLE, message, contentIntentBegin);
			notificationMgr.notify(1, notification);
		} else {
			notification.contentIntent.cancel();
		}
	}


   更多关于PengingIntent 的 大家可以看看 这里。 http://www.7dot9.com/2011/04/android-pendingintent%E7%9A%84%E4%B8%80%E4%BA%9B%E5%B0%8F%E8%BF%B7%E6%83%91/
分享到:
评论

相关推荐

    google_AIP 方法解释

    requestLocationUpdates(String provider, long minTime, float minDistance, PendingIntent intent) 通过给定的Provider名称,周期性地通知当前Activity requestLocationUpdates(String provider, long minTime, ...

    Android中AlarmManager+Notification实现定时通知提醒功能

    AlarmManager实质是一个全局的定时器,是Android中常用的一种系统级别的提示服务,在指定时间或周期性启动其它组件(包括Activity,Service,BroadcastReceiver)。本文将讲解一下如何使用AlarmManager实现定时提醒...

    android 本机定时推送通知

    PendingIntent pi= PendingIntent.getBroadcast(MainActivity.this, 0, new Intent(this,MyReceiver.class), 0); if(b){ // just use current time + 10s as the Alarm time. Calendar c=Calendar....

    Android中通知Notification使用实例(振动、灯光、声音)

    本文实例讲解了通知Notification使用方法,此知识点就是用作通知的显示,包括振动、灯光、声音等效果,分享给大家供大家参考,具体内容如下 效果图: MainActivity: import java.io.File; import android....

    BroadcastTileSupport:一个简单的实现,展示了如何在Android M的System UI Tuner中使用新的“广播图块”

    如果尚未完成操作,请在通知栏中按住“设置”图标约8秒钟。 图标应更改为在齿轮旁边显示扳手。 然后,您会在“设置”末尾看到“系统UI调谐器”选项。 通过系统UI调谐器添加广播图块。 如果您使用的是此存储库中...

    android中创建通知栏Notification代码实例

    ///// 第一步:获取NotificationManager NotificationManager nm = (NotificationManager) getSystemService... //PendingIntent是待执行的Intent PendingIntent pi = PendingIntent.getActivity(this, 0

    Google Android SDK开发范例大全(PDF高清完整版3)(4-3)

    6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少容量...

    android 设置闹钟及通知示例

    简单说一下这次demo内容,首先做一个设置一次性闹钟,先得到alarmManager,打开一个时间对话框,在里面设置闹钟的时间,时间一到发送广播,然后广播接受者接到跳转到新的activity播放音乐。接着是一个反复闹钟,最后...

    Google Android SDK开发范例大全(PDF完整版4)(4-4)

    6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少容量...

    Google Android SDK开发范例大全(PDF高清完整版1)(4-1)

    6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少容量...

    精通ANDROID 3(中文版)1/2

    5.2 Android中可用的Intent  5.3 Intent的组成  5.3.1 Intent和数据URI  5.3.2 一般操作  5.3.3 使用extra信息  5.3.4 使用组件直接调用活动  5.3.5 Intent类别  5.3.6 将Intent解析为组件的规则  ...

    精通Android 3 (中文版)2/2

    5.2 Android中可用的Intent  5.3 Intent的组成  5.3.1 Intent和数据URI  5.3.2 一般操作  5.3.3 使用extra信息  5.3.4 使用组件直接调用活动  5.3.5 Intent类别  5.3.6 将Intent解析为组件的规则  ...

    Google Android SDK开发范例大全(完整版附部分源码).pdf

    6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少...

    Google Android SDK开发范例大全的目录

    6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少容量...

    Google+Android+SDK开发范例大全

    6.4 开始与停止系统服务——Service与Runnable整合并用 6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——...

    Google Android sdk 开发范例大全 部分章节代码

    6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少容量...

    Google Android SDK 开发范例大全01

    6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少容量...

    Google Android SDK 开发范例大全02

    6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少容量...

Global site tag (gtag.js) - Google Analytics