以前在学习AlarmManager里面会遇到PendingIntent,相信大家都知道Intent是你的意图,比如你想启动一个Activity,就会通过 Intent来描述启动这个Activity的某些特点,让系统找到这个Activity来启动,而不是启动别的 Activity.StartActivity(intent)就会立即启动这个Activity.而PendingIntent呢?Penging中文意思就是:待定,将来发生或来临。PendingIntent的就的意思就是不是像Intent那样立即发生,而是在合适的时候才会去触发对应的 Intent.有人说这个intent不是你的ap来触发而是交给别的ap来触发。你可以看以下的code来理解: 这是在PackageInstaller的代码 java代码: private class ClearCacheReceiver extends BroadcastReceiver { public static final String INTENT_CLEAR_CACHE ="com.android.packageinstaller.CLEAR_CACHE"; @Override java代码: if(localLOGV) Log.i(TAG, "Checking for "+size+" number of bytes"); 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());
android.Manifest.permission.CLEAR_APP_CACHE, null); public void run() { retCode = mInstaller.freeCache(freeStorageSize); if (retCode < 0) { if (observer != null) { } |