Intent和PendingIntent的區別

2021-06-16 15:01:11 字數 1863 閱讀 8635

intent英文意思是意圖,pending表示即將發生或來臨的事情。 

pendingintent這個類用於處理即將發生的事情。比如在通知notification中用於跳轉頁面,但不是馬上跳轉。 

intent 是及時啟動,intent 隨所在的activity 消失而消失。

intent一般是用作activity、sercvice、broadcastreceiver之間傳遞資料,而pendingintent,一般用在 notification上,

可以理解為延遲執行的intent

,pendingintent是對intent乙個包裝。 

private void shownotify();出錯?   

"通知", "開會啦", pendingintent.getactivity(this, 0, null, 0));

notice.setlatesteventinfo(this, "通知", "開會啦", pendingintent.getactivity(this, 0, new intent(this,activity2.class), 0));//即將跳轉頁面,還沒跳轉

notificationmanager manager=(notificationmanager)getsystemservice(this.notification_service);

manager.notify(0,notice);

}

private void shownotify();出錯?

"通知", "開會啦", pendingintent.getactivity(this, 0, null, 0));

notice.setlatesteventinfo(this, "通知", "開會啦", pendingintent.getactivity(this, 0, new intent(this,activity2.class), 0));//即將跳轉頁面,還沒跳轉

notificationmanager manager=(notificationmanager)getsystemservice(this.notification_service);

manager.notify(0,notice);

}

1. gsm網路中android傳送簡訊示例

string msg ="你好,美女";   

string number = "135****6784";

smsmanager sms = smsmanager.getdefault();

pendingintent pi = pendingintent.getbroadcast(smsactivity.this,0,new intent(...),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)中引數解釋: 

2)pendingintent deliveryintent:是當訊息已經傳遞給收信人後所進行的pendingintent廣播。 

檢視pendingintent 類可以看到許多的send函式,就是pendingintent在進行被賦予的相關的操作。

Intent和Intent過濾器

intent 是乙個訊息傳遞物件,您可以使用它從其他應用元件請求操作。儘管 intent 可以通過多種方式促進元件之間的通訊,但其基本用例主要包括以下三個 intent startupintent new intent intent.action main startupintent.addcate...

Intent和PendingIntent的區別

intent英文意思是意圖,pending表示即將發生或來臨的事情。pendingintent這個類用於處理即將發生的事情。比如在通知notification中用於跳轉頁面,但不是馬上跳轉。intent 是及時啟動,intent 隨所在的activity 消失而消失。intent一般是用作activ...

Intent使用和Intent過濾器

功能 處理顯式intent和隱式intent 如果元件不含有過濾器,只能接受顯式intent 在使用intent過濾器測試intent物件時,僅測試三個方面 action,data和category 使用方法 配置檔案中標籤內 例外 context.registerreceiver 動態註冊broa...