<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/
分享到:
相关推荐
requestLocationUpdates(String provider, long minTime, float minDistance, PendingIntent intent) 通过给定的Provider名称,周期性地通知当前Activity requestLocationUpdates(String provider, long minTime, ...
AlarmManager实质是一个全局的定时器,是Android中常用的一种系统级别的提示服务,在指定时间或周期性启动其它组件(包括Activity,Service,BroadcastReceiver)。本文将讲解一下如何使用AlarmManager实现定时提醒...
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....
本文实例讲解了通知Notification使用方法,此知识点就是用作通知的显示,包括振动、灯光、声音等效果,分享给大家供大家参考,具体内容如下 效果图: MainActivity: import java.io.File; import android....
如果尚未完成操作,请在通知栏中按住“设置”图标约8秒钟。 图标应更改为在齿轮旁边显示扳手。 然后,您会在“设置”末尾看到“系统UI调谐器”选项。 通过系统UI调谐器添加广播图块。 如果您使用的是此存储库中...
///// 第一步:获取NotificationManager NotificationManager nm = (NotificationManager) getSystemService... //PendingIntent是待执行的Intent PendingIntent pi = PendingIntent.getActivity(this, 0
6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少容量...
简单说一下这次demo内容,首先做一个设置一次性闹钟,先得到alarmManager,打开一个时间对话框,在里面设置闹钟的时间,时间一到发送广播,然后广播接受者接到跳转到新的activity播放音乐。接着是一个反复闹钟,最后...
6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少容量...
6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少容量...
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解析为组件的规则 ...
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解析为组件的规则 ...
6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少...
6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少容量...
6.4 开始与停止系统服务——Service与Runnable整合并用 6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——...
6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少容量...
6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少容量...
6.5 通过短信发送email通知——BroadcastReceiver与Intent整合 6.6 手机拨接状态——PhoneStateListener之onCallStateChanged 6.7 有来电,发送邮件通知——PhoneStateListener与ACTION_SEND 6.8 存储卡剩余多少容量...