- 浏览: 1055747 次
- 性别:
- 来自: 南昌
文章分类
- 全部博客 (276)
- 生活 (1)
- 代码之美 (22)
- Media (7)
- Android Widget (3)
- Android Intent (1)
- Android Activity (4)
- UI event handle--UI事件处理机制 (2)
- Java基础知识 (12)
- android Databases (5)
- Android 系统知识 (70)
- 平常遇到的问题与解决方法 (38)
- Android TextView/EditView (2)
- Thinking Java (1)
- android webkit (6)
- JSON (1)
- XML (4)
- HTTP (1)
- Google Weather API (1)
- android 2.3 NFC (10)
- android app (20)
- android framework (7)
- C++ (2)
- android System (5)
- Pthread (1)
- Wifi (8)
- Unix/Linux C (8)
- Android 4.0 (1)
- Mail (1)
- Smack 源码学习 (4)
- iOS (4)
- Android (1)
- git (1)
- Gallery3d (2)
- React-Natice (1)
最新评论
-
dd18349182956:
你是用的smack哪个版本?我用的smack4.1.3和sma ...
关于socket长连接的心跳包 -
xukaiyin:
全英文
getApplicationContext()与this,getBaseContext() -
裂风矢:
...
<category android:name="android.intent.category.DEFAULT" /> 惹的祸 -
xanthodont:
mark一下
XMPP——Smack -
Evilover3:
mark一下,学习了
XMPP——Smack
以前在学习AlarmManager里面会遇到PendingIntent,我就很迷惑,PendingIntent和Intent的区别是什么呢?我在网上搜索了,但看了许多人的解释还是不理解,今天有看到了PendingIntent的另一种用法,所以我重新理解一遍PendingIntent.不知道是否理解正确,只是把自己的理解写出来,大家一起共同探讨。相信大家都知道Intent是你的意图,比如你想启动一个Activity,就会通过Intent来描述启动这个Activity的某些特点,让系统找到这个Activity来启动,而不是启动别的Activity.StartActivity(intent)就会立即启动这个Activity.而PendingIntent呢?Penging中文意思就是:待定,将来发生或来临。PendingIntent的就的意思就是不是像Intent那样立即发生,而是在合适的时候才会去触发对应的Intent.有人说这个intent不是你的ap来触发而是交给别的ap来触发。你可以看以下的code来理解:
这是在PackageInstaller的代码
mPm.freeStorage(size, pi.getIntentSender());
以下是在PackageManagerService的:
opFinishedIntent.send((retCode >= 0) ? 1 : 0);在PackageInstaller定义的PendingIntent,在PackageManagerService里面来触发。
不是很懂你的问题哦!
朋友,我已经增加了一点点注解,希望对你有帮助。有时候,有些东西是"只可意会不可言传滴"
这是在PackageInstaller的代码
private class ClearCacheReceiver extends BroadcastReceiver { public static final String INTENT_CLEAR_CACHE = "com.android.packageinstaller.CLEAR_CACHE"; @Override public void onReceive(Context context, Intent intent) { Message msg = mHandler.obtainMessage(FREE_SPACE); msg.arg1 = (getResultCode() ==1) ? SUCCEEDED : FAILED; mHandler.sendMessage(msg); } }
private void checkOutOfSpace(long size) { if(localLOGV) Log.i(TAG, "Checking for "+size+" number of bytes"); if (mClearCacheReceiver == null) { mClearCacheReceiver = new ClearCacheReceiver(); } registerReceiver(mClearCacheReceiver, new IntentFilter(ClearCacheReceiver.INTENT_CLEAR_CACHE)); PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(ClearCacheReceiver.INTENT_CLEAR_CACHE), 0); mPm.freeStorage(size, pi.getIntentSender()); }
mPm.freeStorage(size, pi.getIntentSender());
以下是在PackageManagerService的:
public void freeStorage(final long freeStorageSize, final PendingIntent opFinishedIntent) { mContext.enforceCallingOrSelfPermission( android.Manifest.permission.CLEAR_APP_CACHE, null); // Queue up an async operation since clearing cache may take a little while. mHandler.post(new Runnable() { public void run() { mHandler.removeCallbacks(this); int retCode = -1; if (mInstaller != null) { retCode = mInstaller.freeCache(freeStorageSize); if (retCode < 0) { Log.w(TAG, "Couldn't clear application caches"); } } if(opFinishedIntent != null) { try { // Callback via pending intent opFinishedIntent.send((retCode >= 0) ? 1 : 0); } catch (CanceledException e1) { Log.i(TAG, "Failed to send pending intent"); } } } }); }
opFinishedIntent.send((retCode >= 0) ? 1 : 0);在PackageInstaller定义的PendingIntent,在PackageManagerService里面来触发。
评论
4 楼
追求幸福
2011-07-06
h286271819 写道
怎么实现对第三方应用程序的缓存清理啊????
不是很懂你的问题哦!
3 楼
h286271819
2011-07-06
怎么实现对第三方应用程序的缓存清理啊????
2 楼
追求幸福
2010-11-09
rmn190 写道
下面没有啦?就这么点干巴巴的代码, 哇呀呀....
朋友,我已经增加了一点点注解,希望对你有帮助。有时候,有些东西是"只可意会不可言传滴"
1 楼
rmn190
2010-11-05
下面没有啦?就这么点干巴巴的代码, 哇呀呀....
发表评论
-
打印调用堆栈
2019-11-15 15:48 445平常我们遇到不清楚代码逻辑的,可以通过打印调用堆栈来理清楚,如 ... -
你知道Log.isLoggable
2018-11-23 14:15 841我们可以通过Log.isLoggable来动态开关log的输出 ... -
android:allowUndo
2018-04-25 16:51 752Android 在Android 23增加了UndoManag ... -
mipmap-xxx
2015-12-10 11:35 1062最近在看AOSP,发现mipmaps, 百度 了一下,发现有各 ... -
《Android.Programming.Pushing.the.Limits].Erik.Hellman》记录1
2015-10-29 10:56 551最近在看《Android.Programming.Pushin ... -
System.currentTimeMillis() uptimeMillis elapsedRealtime 区别
2015-10-28 20:02 1274转自http://blog.csdn.net/wutianyi ... -
GPS的开关设置
2015-09-29 18:36 1982//modify by hyxu 2015-9-30 to s ... -
DialogFragment
2015-09-25 13:56 1009public class YesNoDialog extend ... -
ANDROID L——RecyclerView,CardView导入和使用
2015-07-23 09:51 917转自http://blog.csdn.net/a3969019 ... -
IntentService 和ResultReceiver
2015-07-22 20:00 786转自[url] http://javatechig.com/a ... -
Android media媒体库分析之:分类别统计媒体文件大小
2015-07-21 20:07 526转自http://www.linuxidc.com/Linux ... -
java.lang.IllegalArgumentException: Service Intent must be explicit
2015-07-21 20:03 1278转自:http://www.2cto.com/kf/20150 ... -
Context 和Application Context
2015-02-11 15:14 863http://possiblemobile.com/2013/ ... -
ContentProviderOperation.Builder 中withValue和withValueBackReference的区别
2015-02-10 14:01 2177关于ContentProviderOperation.Buil ... -
AndroidManifest.xml的Service元素 android:process设置
2013-05-30 17:02 11460转自:http://galin.blog.sohu ... -
android中打包含有Activity以及资源文件的jar包在工程中调用
2013-05-28 15:00 1293转自:http://www.cnblogs.com/vaiya ... -
Android杂谈--内存泄露(1)--contentView缓存使用与ListView优化
2012-11-01 09:29 2799转自:http://www.cnblogs.com/louli ... -
Handler+ExecutorService(线程池)+MessageQueue模式+缓存模式
2012-10-31 14:32 1857转自:http://www.eoeandroid.com/th ... -
Animation
2012-10-30 13:41 1109转自:http://hi.baidu.com/wendaoer ... -
Android onTouchEvent和onInterceptTouchEvent
2012-10-24 15:05 1262ViewGroup里的onInterceptTouchEven ...
相关推荐
简单的总结了Intent和PendtingIntent的区别,经常与alermanger 和notificationmanager一起使用。
这样我们就可以画出如下示意图:PendingIntent 只能通过下列的静态方法获取//获取Broadcast关联的PendingIntent PendingI
要得到一个pendingIntent对象,使用方法类的静态方法 getActivity(Context, int, Intent, int),getBroadcast(Context, int, Intent, int),getService(Context, int, Intent, int) 分别对应着Intent的3个行为,跳转...
Android中pendingIntent的深入理解
Android Proximity Alert 手机接近进警告或提示... PendingIntent pi = PendingIntent.getBroadcast(this, -1, intent, 0); //添加接近警告 lm.addProximityAlert(latitude, longitude, radius, -1, pi);
归纳了Intent入 的4种形式:Intent转换与复制、 Action/Component/Data注 、PendingIntent误用与 parseUri注 入 归纳了利用自动化的工具具发现这4类形式的方法,通过批 量的扫描,可以轻易发现这些漏洞 在每种都找到了...
Notification的用法和PendingIntent的使用
博客《详解PendingIntent》所涉及的源码,这是博客中所说的有问题的PendingIntent对应原源代码
实现可定时响起的闹钟----PendingIntent 与 AlarmManager 的运用
NULL 博文链接:https://sunzone.iteye.com/blog/1998091
PendingIntent 分别实现了Notification和sms短信发送的两个示例
自制发送短信程序--SmsManager与PendingIntent类的使用
android的服务以及通知的小例子 个人存档 代码笔记见http://blog.sina.com.cn/s/blog_70356c200100y9pf.html
博客《详解PendingIntent》有问题的源码第二部分
要用 android.app.PendingIntent.getBroadcast(Context context, int requestCode, Intent intent)来实现控制多个闹钟,关键点在于其中的一个参数requestCode. 举例说明如下: public void setClock(){ if(lva....
double latitude, double longitude, float radius, long expiration, PendingIntent intent) 添加一个趋近警告 getAllProviders() 获得所有的LocationProvider列表 getBestProvider(Criteria criteria, ...
android 自制发送短信程序 SmsManager与PendingIntent对象
PendingIntent mPI = PendingIntent.getBroadcast(EX05_03.this, 0, new Intent(), 0); smsManager.sendTextMessage(strDestAddress, null, strMessage, mPI, null); } catch(Exception e) { e....
NULL 博文链接:https://technicalsearch.iteye.com/blog/2007636