- 浏览: 250716 次
- 性别:
- 来自: 苏州
文章分类
- 全部博客 (289)
- java (72)
- oracle (3)
- mysql (5)
- spring (28)
- hibernate (2)
- osgi (0)
- linux (2)
- ExtJs (1)
- jvm (0)
- mybatis (7)
- 分布式 (11)
- MINA (6)
- apache+tomcat (13)
- js+htm (7)
- android (44)
- http (1)
- hbase+hdoop (0)
- memcache (13)
- search (27)
- 部署及性能 (12)
- mongoDB (2)
- 多线程 (12)
- 安全管理验证 (9)
- struts (1)
- webservice (0)
- easyUI (1)
- spring security (16)
- pattern (6)
- 算法 (2)
最新评论
-
lzh8189146:
CommonsHttpSolrServer这个类,现在是不是没 ...
CommonsHttpSolrServer -
xiaochanzi:
我按照你的方法试了下,tomcat6可以发布,但是访问任何网页 ...
基于内嵌Tomcat的应用开发 -
phoneeye:
麻烦你,如果是抄来的文章,请给出来源。谢谢
ant 两则技巧 -
neverforget:
转载不注明出处
Spring Security3.1登陆验证 替换 usernamepasswordfilter -
liang1022:
若不使用eclipse ,如何在命令行下 运行服务端程序 ?
WebService CXF学习(入门篇2):HelloWorld
Intent和PendingIntent的区别 (2011-10-09 08:56:08)转载▼
标签: intent pendintent 杂谈 分类: 手机世界
Intent 和PendingIntent
Intent和PendingIntent的关系,初学的时候很迷惑,用PendingIntent的时候,还会出现奇怪的问题,比如无法传递数据,无法更新数据,所以我集众家之长,加上我个人的一些实践,总结如下,希望能给你一些帮助。
首先看官方解释:An Intent is something that is used right now; a PendingIntent is something that may create an Intent in the future. You will use a PendingIntent with Notifications, AlarmManager, etc.
Intent大家都很熟悉了,就是一个意图,这个意图表明要启动哪个Activity,Service,PendingIntent可以看作是对Intent的进一步封装,它是对Intent的描述,我们可以把这个描述交给别的程序,别的程序根据这个描述在后面的时间做你安排做的事情,下面是一个发送SMS短信的例子:
String msg ="你好";
String number = "135****6784";
SmsManager sms = SmsManager.getDefault();
PendingIntent pi = PendingIntent.getBroadcast(SmsActivity.this,0,new Intent(XXX),0);
sms.sendTextMessage(number, null, msg, pi, null);
Toast.makeText(SmsActivity.this,"发送成功",Toast.LENGHT_LONG).show();
方法SmsManager.sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent):短信发送成功,进行通知
PendingIntent sentIntent:当短信发出时,成功的话sendIntent会把其内部的描述的intent广播出去,当然失败之后会产生错误代码,并通过 android.app.PendingIntent.OnFinished进行回调("Callback");
PendingIntent deliveryIntent:是当消息已经传递给收信人后所进行的Intent广播;
如果你的BroadcastReveiver注册接收相应的消息,你就会收到相应的Intent,这时候就可以根据Intent的Action,执行相应的动作,这就是上面说的in the future的含义;
有三个静态方法可以获得PendingIntent实例:
public static PendingIntent getBroadcast(Context context, int requestCode, Intent intent, int flags)
public static PendingIntent getActivity(Context context, int requestCode, Intent intent, int flags)
public static PendingIntent getService(Context context, int requestCode, Intent intent, int flags)
flags参数有三个,我觉得英文更好理解:
FLAG_ONE_SHOT:this PendingIntent can only be used once. If set, after send() is called on it, it will be automatically canceled for you and any future attempt to send through it will fail.
FLAG_UPDATE_CURRENT: if the described PendingIntent already exists, then keep it but its replace its extra data with what is in this new Intent. This can be used if you are creating intents where only the extras change, and don't care that any entities that received your previous PendingIntent will be able to launch it with your new extras even if they are not explicitly given to it.
这个简单解释一下,就是当存在时,先把原来的取消,然后创建一个新的,在AlarmManager服务时,修改一个闹铃,用的比较笨的的方法,先取消,然后重新注册,其实加上这个参数就行了。
要注意的是,这个只更新extra data,不会修改其他内容,不能new一个Intent,还有就是如果你的Intent中需要传递Id或者其他数据,一定要用这个flags或者FLAG_CANCEL_CURRENT,曾经一直接收不到Id,查了半天原来是这个原因 :-(
LAG_NO_CREATE:if the described PendingIntent does not already exist, then simply return null instead of creating it.
LAG_CANCEL_CURRENT:if the described PendingIntent already exists, the current one is canceled before generating a new one.You can use this to retrieve a new PendingIntent when you are only changing the extra data in the Intent; by canceling the previous pending intent, this ensures that only entities given the new data will be able to launch it. If this assurance is not an issue, consider FLAG_UPDATE_CURRENT.
上面4个flag中最经常使用的是FLAG_UPDATE_CURRENT,因为描述的Intent有更新的时候需要用到这个flag去更新你的描述(确切的说是更新extra data),否则组件在下次事件发生或时间到达的时候extras永远是第一次Intent的extras,使用FLAG_CANCEL_CURRENT也能做到更新extras,只不过是先把前面的extras清除,另外FLAG_CANCEL_CURRENT和FLAG_UPDATE_CURRENT的区别在于能否新new一个Intent,FLAG_CANCEL_CURRENT能够新new一个Intent,而FLAG_UPDATE_CURRENT则不能,只能使用第一次的Intent。
还有一个问题就是怎么区分PendingIntent,主要取消的时候要用到,requestCode可以区分,但系统还是根据Intent的Action去区分的,如果Intent设置了Class,classData,取消的时候Intent一定要设置要相同的,不然取消不掉就可能出现取消后,Alarm还会响的问题,PendingIntent用的地方蛮多的,像 Notifications, AlarmManager等都会用到。。。
标签: intent pendintent 杂谈 分类: 手机世界
Intent 和PendingIntent
Intent和PendingIntent的关系,初学的时候很迷惑,用PendingIntent的时候,还会出现奇怪的问题,比如无法传递数据,无法更新数据,所以我集众家之长,加上我个人的一些实践,总结如下,希望能给你一些帮助。
首先看官方解释:An Intent is something that is used right now; a PendingIntent is something that may create an Intent in the future. You will use a PendingIntent with Notifications, AlarmManager, etc.
Intent大家都很熟悉了,就是一个意图,这个意图表明要启动哪个Activity,Service,PendingIntent可以看作是对Intent的进一步封装,它是对Intent的描述,我们可以把这个描述交给别的程序,别的程序根据这个描述在后面的时间做你安排做的事情,下面是一个发送SMS短信的例子:
String msg ="你好";
String number = "135****6784";
SmsManager sms = SmsManager.getDefault();
PendingIntent pi = PendingIntent.getBroadcast(SmsActivity.this,0,new Intent(XXX),0);
sms.sendTextMessage(number, null, msg, pi, null);
Toast.makeText(SmsActivity.this,"发送成功",Toast.LENGHT_LONG).show();
方法SmsManager.sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent):短信发送成功,进行通知
PendingIntent sentIntent:当短信发出时,成功的话sendIntent会把其内部的描述的intent广播出去,当然失败之后会产生错误代码,并通过 android.app.PendingIntent.OnFinished进行回调("Callback");
PendingIntent deliveryIntent:是当消息已经传递给收信人后所进行的Intent广播;
如果你的BroadcastReveiver注册接收相应的消息,你就会收到相应的Intent,这时候就可以根据Intent的Action,执行相应的动作,这就是上面说的in the future的含义;
有三个静态方法可以获得PendingIntent实例:
public static PendingIntent getBroadcast(Context context, int requestCode, Intent intent, int flags)
public static PendingIntent getActivity(Context context, int requestCode, Intent intent, int flags)
public static PendingIntent getService(Context context, int requestCode, Intent intent, int flags)
flags参数有三个,我觉得英文更好理解:
FLAG_ONE_SHOT:this PendingIntent can only be used once. If set, after send() is called on it, it will be automatically canceled for you and any future attempt to send through it will fail.
FLAG_UPDATE_CURRENT: if the described PendingIntent already exists, then keep it but its replace its extra data with what is in this new Intent. This can be used if you are creating intents where only the extras change, and don't care that any entities that received your previous PendingIntent will be able to launch it with your new extras even if they are not explicitly given to it.
这个简单解释一下,就是当存在时,先把原来的取消,然后创建一个新的,在AlarmManager服务时,修改一个闹铃,用的比较笨的的方法,先取消,然后重新注册,其实加上这个参数就行了。
要注意的是,这个只更新extra data,不会修改其他内容,不能new一个Intent,还有就是如果你的Intent中需要传递Id或者其他数据,一定要用这个flags或者FLAG_CANCEL_CURRENT,曾经一直接收不到Id,查了半天原来是这个原因 :-(
LAG_NO_CREATE:if the described PendingIntent does not already exist, then simply return null instead of creating it.
LAG_CANCEL_CURRENT:if the described PendingIntent already exists, the current one is canceled before generating a new one.You can use this to retrieve a new PendingIntent when you are only changing the extra data in the Intent; by canceling the previous pending intent, this ensures that only entities given the new data will be able to launch it. If this assurance is not an issue, consider FLAG_UPDATE_CURRENT.
上面4个flag中最经常使用的是FLAG_UPDATE_CURRENT,因为描述的Intent有更新的时候需要用到这个flag去更新你的描述(确切的说是更新extra data),否则组件在下次事件发生或时间到达的时候extras永远是第一次Intent的extras,使用FLAG_CANCEL_CURRENT也能做到更新extras,只不过是先把前面的extras清除,另外FLAG_CANCEL_CURRENT和FLAG_UPDATE_CURRENT的区别在于能否新new一个Intent,FLAG_CANCEL_CURRENT能够新new一个Intent,而FLAG_UPDATE_CURRENT则不能,只能使用第一次的Intent。
还有一个问题就是怎么区分PendingIntent,主要取消的时候要用到,requestCode可以区分,但系统还是根据Intent的Action去区分的,如果Intent设置了Class,classData,取消的时候Intent一定要设置要相同的,不然取消不掉就可能出现取消后,Alarm还会响的问题,PendingIntent用的地方蛮多的,像 Notifications, AlarmManager等都会用到。。。
发表评论
-
android之ConnectivityManager简介,网络连接状态
2012-09-13 10:56 908转发:http://blog.csdn.net/chenzhe ... -
解决Android布局中ScrollView与ListView的冲突
2012-08-27 09:25 713http://06peng.com/read.php/7.ht ... -
APK_获取Android的APK包签名信息
2012-08-02 14:09 1253http://blog.csdn.net/jiguanghov ... -
Android系列之Android 命令行手动编译打包详解
2012-08-01 22:08 874http://blog168.chinaunix.net/sp ... -
Android屏幕锁定详解(一)
2012-06-17 21:35 784http://mzh3344258.blog.51cto.co ... -
android 获取手机通讯录信息
2012-06-15 17:28 1079android 获取手机通讯录信息 博客分类: androi ... -
Android Intent.ACTION_CHOOSER 与 Intent.ACTION_PICK_ACTIVITY
2012-06-15 14:02 1402http://blog.csdn.net/feng88724/ ... -
Android绘制进阶之一:图形的绘制
2012-06-15 11:28 716http://mikewang.blog.51cto.com/ ... -
Android画图之Matrix(一)
2012-06-14 16:53 677http://chroya.iteye.com/blog/71 ... -
Android Bitmap和Canvas学习笔记 Android Bitmap和Canvas学习笔记
2012-06-14 14:04 694http://www.pin5i.com/showtopic- ... -
Paint类介绍
2012-06-14 13:41 664** * Paint类介绍 * ... -
Android Activity和Intent机制学习笔记 打电话,发短信等练习
2012-06-12 13:22 1074http://ycl248.blog.163.com/blog ... -
taskAffinity属性
2012-06-12 13:22 657taskAffinity属性 分类: Android 2011 ... -
区分Activity的四种加载模式----以及Intent的setFlags
2012-06-12 13:22 675区分Activity的四种加载模式----以及Intent的s ... -
android 自带的主题 theme 的使用
2012-06-12 13:22 1114android 自带的主题 theme 的使用 2011 ... -
TextView小组件的使用--附带超链接和跑马灯效果
2012-06-07 08:40 777TextView小组件的使用--附带超链接和跑马灯效果 分类: ... -
EditText使用详解
2012-06-07 08:40 827EditText使用详解 分类: ... -
(转)解决requestFocus后依旧无法获得焦点问题
2012-06-07 08:40 1401(转)解决requestFocus后依旧无法获得焦点问题 博 ... -
android 在程序中开启GPS功能
2012-06-07 08:40 1043android 在程序中开启GPS功能 LocationMan ... -
转到手机设置界面
2012-06-06 16:34 0//转到手机设置界面 Intent intent=new In ...
相关推荐
这样我们就可以画出如下示意图:PendingIntent 只能通过下列的静态方法获取//获取Broadcast关联的PendingIntent PendingI
Notification的用法和PendingIntent的使用
主要介绍了Android中pendingIntent的深入分析的相关资料,需要的朋友可以参考下
归纳了Intent入 的4种形式:Intent转换与复制、 Action/Component/Data注 、PendingIntent误用与 parseUri注 入 归纳了利用自动化的工具具发现这4类形式的方法,通过批 量的扫描,可以轻易发现这些漏洞 在每种都找到了...
PendingIntent 分别实现了Notification和sms短信发送的两个示例
PendingIntent pi = PendingIntent.getBroadcast(Sample_12_7.this, 0, intent, 0); //创建PendingIntent am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pi);//设置闹钟 Toast.makeText(Sample...
要用 android.app.PendingIntent.getBroadcast(Context context, int requestCode, Intent intent)来实现控制多个闹钟,关键点在于其中的一个参数requestCode. 举例说明如下: public void setClock(){ if(lva....
pendingIntent=PendingIntent.getActivity(MainActivity.this, 0, intent, 0); calendar=Calendar.getInstance(); alarmManager=(AlarmManager) getSystemService(ALARM_SERVICE); } public void...
另一个是利用Intent传递广播的Intent的时候,传参数的时候,记得设置PendingIntent sender=PendingIntent.getBroadcast(context,0, intent1, PendingIntent.FLAG_UPDATE_CURRENT);的PendingIntent.FLAG_UPDATE_...
Intent itSend = new Intent(SMS_SEND_ACTIOIN); Intent itDeliver = new Intent(SMS_DELIVERED_ACTION); PendingIntent mSendPI = PendingIntent.getBroadcast(context, 0, itSend, 0); ...
Android Proximity Alert 手机接近进警告或提示... PendingIntent pi = PendingIntent.getBroadcast(this, -1, intent, 0); //添加接近警告 lm.addProximityAlert(latitude, longitude, radius, -1, pi);
通过 PendingIntent 切换活动 这是一个小项目,用于演示通过正常调用 startActivity 在活动之间切换工作正常,但是当我在 PendingIntent 中发送带有该标志的意图然后调用mPendingIntent.send()该标志似乎是忽略:-(。...
PendingIntent mPI = PendingIntent.getBroadcast(EX05_03.this, 0, new Intent(), 0); smsManager.sendTextMessage(strDestAddress, null, strMessage, mPI, null); } catch(Exception e) { e....
当一个application 中有多个 Activity的时候,那么每个Activity之前的传值就是一...1.实体类 Intent 、Context 、 BroadcastReceiver 2.方法类 PendingIntent Context.sendBroadcast 传递的方法 也就是方法类中的两种
本文实例为大家分享了Intent实现页面跳转的两种的方法,供大家参考,具体内容如下 下图中两个不同的方法就是两种页面之间跳转的情况 1).跳转不返回数据 2).跳转返回数据 实例: 第一种启动方式(跳转不返回数据) ...
double latitude, double longitude, float radius, long expiration, PendingIntent intent) 添加一个趋近警告 getAllProviders() 获得所有的LocationProvider列表 getBestProvider(Criteria criteria, ...
PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0); // 开始时间 long firstime = SystemClock.elapsedRealtime(); // 60秒一个周期,不停的发送广播 // am....
极光推送(自定义消息)