第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

安卓PendingIntent介紹

標(biāo)簽:
Android

Pending表示即将发生或来临的事情,我们知道,Intent是安卓内部组件传递信息的媒介,而PendingIntent 可以看作是对Intent的包装,通常通过getActivity,getBroadcast ,getService来得到pendingintent的实例,当前activity并不能马上启动它所包含的intent,而是在外部执行PendingIntent时,调用intent的。正由于PendingIntent中保存有当前App的Context,使它赋予外部App一种能力,使得外部App可以如同当前App一样的执行PendingIntent里的 Intent, 就算在执行时当前App已经不存在了,也能通过存在pendingintent里的Context照样执行Intent。另外还可以处理intent执行后的操作。常和AlarmManger 和Notification一起使用。 Intent一般是用作Activity、Sercvice、BroadcastReceiver之间传递数据,而Pendingintent,一般用在 Notification上,可以理解为延迟执行的Intent。

示例:


public void showNotify(){
        NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        long when = System.currentTimeMillis() + 2000;
        Intent intent = new Intent(this, SecondActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        //在API 11之后推荐使用此方法构建Notification
        NotificationCompat.Builder ncb = new NotificationCompat.Builder(MainActivity.this);
        ncb.setTicker("第一个Notifiy");
        ncb.setAutoCancel(true);
        ncb.setContentIntent(pendingIntent);
        ncb.setDefaults(Notification.DEFAULT_ALL);
        ncb.setContentTitle("提醒");
        ncb.setContentText("这是一条PendingIntent提醒");
        ncb.setSmallIcon(R.mipmap.ic_launcher);
        ncb.setWhen(when);
        nm.notify(0, ncb.build()); }
點(diǎn)擊查看更多內(nèi)容
2人點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
移動(dòng)開(kāi)發(fā)工程師
手記
粉絲
8
獲贊與收藏
13

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶(hù)
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專(zhuān)欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消