Android中通知欄跳動(dòng)問(wèn)題解決方法
曾經(jīng)遇到過(guò)這樣的問(wèn)題,在我的代碼中使用了通知欄,一切都正常,但是就是正在進(jìn)行的通知欄中屬于我的程序的那一條總是上下跳來(lái)跳去,一閃一閃的。感覺(jué)用戶體驗(yàn)很不好,于是Google一下,找到了解決方法。
在我的代碼,我是這樣寫(xiě)的。
notification.when = System.currentTimeMillis();
這就是問(wèn)題的關(guān)鍵,對(duì)于通知來(lái)說(shuō),when這個(gè)屬性值應(yīng)該在activity一啟動(dòng)的時(shí)候就應(yīng)該固定。如果沒(méi)有固定,就會(huì)使用默認(rèn)的值,默認(rèn)的值就是當(dāng)前的時(shí)間,即System.currentTimeMillis()的值。因此使用一個(gè)自定義的固定值就可以解決問(wèn)題。
final long TIMESTAMP_FIXED = 1234567890l;
notification.when = TIMESTAMP_FIXED;
以下如Google介紹如何使用notification的when的說(shuō)明。
A timestamp related to this notification, in milliseconds since the epoch. Default value: Now. Choose a timestamp that will be most relevant to the user. For most finite events, this corresponds to the time the event happened (or will happen, in the case of events that have yet to occur but about which the user is being informed). Indefinite events should be timestamped according to when the activity began. Some examples:
Notification of a new chat message should be stamped when the message was received.
Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.
Notification of a completed file download should be stamped when the download finished.
Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).
Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time.
Notification of an ongoing countdown timer should be stamped with the timer's end time.
Reference
http://developer.android.com/reference/android/app/Notification.html#when
相關(guān)文章
Android編程之短信竊聽(tīng)器實(shí)現(xiàn)方法
這篇文章主要介紹了Android編程之短信竊聽(tīng)器實(shí)現(xiàn)方法,以實(shí)例形式較為詳細(xì)的分析了Android編程實(shí)現(xiàn)竊聽(tīng)器的具體步驟與實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11Android實(shí)現(xiàn)環(huán)形進(jìn)度條代碼
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)環(huán)形進(jìn)度條的代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01Android EditText實(shí)現(xiàn)輸入表情
editText是TextView的子類,TextView能用的工具EditText都能用,接下來(lái)通過(guò)實(shí)例代碼給大家分享Android EditText實(shí)現(xiàn)輸入表情功能,感興趣的朋友一起看看吧2017-08-08Android Selector 按下修改背景和文本顏色的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android Selector 按下修改背景和文本顏色的實(shí)現(xiàn)代碼,本文通過(guò)實(shí)例代碼和demo展示給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-11-11Android原生實(shí)現(xiàn)多線程斷點(diǎn)下載實(shí)例代碼
本篇文章主要介紹了Android原生實(shí)現(xiàn)多線程斷點(diǎn)下載實(shí)例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05Android對(duì)EditTex的圖片實(shí)現(xiàn)監(jiān)聽(tīng)
這篇文章主要為大家詳細(xì)介紹了Android如何對(duì)EditTex的圖片實(shí)現(xiàn)監(jiān)聽(tīng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10Android自定義圓形View實(shí)現(xiàn)小球跟隨手指移動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了Android自定義圓形View實(shí)現(xiàn)小球跟隨手指移動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03Flutter自定義實(shí)現(xiàn)神奇動(dòng)效的卡片切換視圖的示例代碼
這篇文章主要介紹了Flutter自定義實(shí)現(xiàn)神奇動(dòng)效的卡片切換視圖的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-04-04Android編程實(shí)現(xiàn)微信分享信息的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)微信分享信息的方法,實(shí)例分析了Android官方demo示例,講述了Android微信分享功能的具體實(shí)現(xiàn)技巧,需要的朋友可以參考下2015-10-10Android自定義view實(shí)現(xiàn)側(cè)滑欄詳解
之前一直沒(méi)有寫(xiě)側(cè)滑菜單的實(shí)現(xiàn)方法,今天計(jì)劃補(bǔ)上。手機(jī)開(kāi)發(fā)中,往往存在很多功能沒(méi)處放的問(wèn)題。我們可能會(huì)把功能放入一個(gè)菜單列表,但現(xiàn)在一種流行的做法是側(cè)滑菜單2022-11-11