Android難題 :如何判斷兩個PendingIntent是否相同?

來源:互聯網
上載者:User

標籤:android   io   ar   java   sp   on   問題   bs   ad   

============問題描述============


再做一個鬧鈴服務,
我在A類裡面通過

PendingIntent pi_1=PendingIntent
.getBroadcast(context, re_1.getAlarm_id(), intent_1, 0);
aManager.set(AlarmManager.RTC_WAKEUP, notifyDate_1, pi_1);來建立一個提醒服務,
我又在一個類中將通過intent複原PendingIntent,然後取消: aManager.cancel(pi);
結果老是報告:NullPointerException
請問:
          1.如何判斷兩個PendingIntent是否相同,若不同如何查處不同之處?。

============解決方案1============


“將通過intent複原PendingIntent”是什麼意思?
要取消的話,直接建立PendingIntent取消就可以了:
PendingIntent pi = PendingIntent.getBroadcast(context, re_1.getAlarm_id(), intent_1, 0);AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);alarmManager.cancel(pi);

============解決方案2============


取消時的PendingIntent要和建立時的一樣。像樓上的取消時建立一個和建立時相同的PendingIntent。包括參數。

Android難題 :如何判斷兩個PendingIntent是否相同?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.