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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Parcelable 對(duì)象通過通知被接收為空,但在活動(dòng)之間工作

Parcelable 對(duì)象通過通知被接收為空,但在活動(dòng)之間工作

富國滬深 2021-11-11 16:02:49
我有一個(gè)名為 ParserService 的意圖服務(wù),它執(zhí)行一些任務(wù)并創(chuàng)建一個(gè)可打包的對(duì)象(ArtistInfo)。然后它檢查應(yīng)用程序是否在前臺(tái)。如果是,則它會(huì)在意圖附加項(xiàng)中發(fā)送帶有可分割對(duì)象的廣播。此廣播由活動(dòng) MainActivity.java 接收,然后該活動(dòng)創(chuàng)建具有相同對(duì)象的意圖,并啟動(dòng)名為 ListSongsActivity 的活動(dòng),在該活動(dòng)中成功接收了 Parcelable 對(duì)象。但是,如果應(yīng)用程序不在前臺(tái),則 ParserService 會(huì)發(fā)送一個(gè)通知,其意圖與廣播的意圖相同。但是當(dāng) ListSongsActivity 通過通知啟動(dòng)時(shí),parcelable 對(duì)象(ArtistInfo)這次為空。我也在意圖中傳遞一個(gè)字符串。該字符串通過通知意圖正確接收,但parcelable 對(duì)象為空。請(qǐng)?jiān)谙旅嬲业较嚓P(guān)的代碼片段。來自 ParserService 的廣播和通知代碼:if (CommonUtils.appInForeground(getApplicationContext())) {                Log.d(TAG, "onHandleIntent(): Sending success broadcast.");                sendBroadcast(createSuccessIntent(artistInfo));            } else {                // TODO: 10-10-2018 tapping on notification does nothing!!                Log.d(TAG, "onHandleIntent(): Sending success notification.");                String body = "Parsing complete for the url: " + url;                Intent notifyIntent = new Intent(getApplicationContext(), ListSongsActivity.class);                notifyIntent.putExtra(Constants.MUSIC_SITE, siteName);                notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);                Bundle bundle = new Bundle();                bundle.putParcelable(Constants.PARSED_ARTIST_INFO, artistInfo);                intent.putExtras(bundle);                CommonUtils.sendNotification(getApplicationContext(), Constants.LIST_SONGS_NOTIFICATION_TITLE                        , body, Constants.LIST_SONGS_NOTIFICATION_CHANNEL_ID, notifyIntent,                        Constants.LIST_SONGS_NOTIFICATION_ID, R.drawable.ic_launcher_background);            }private Intent createSuccessIntent(ArtistInfo artistInfo) {    Intent intent = new Intent();    intent.setAction(Constants.PARSE_SUCCESS_ACTION_KEY);    Bundle bundle = new Bundle();    bundle.putParcelable(Constants.PARSE_SUCCESS_MESSAGE_KEY, artistInfo);    intent.putExtras(bundle);    return intent;}
查看完整描述

2 回答

?
皈依舞

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超3個(gè)贊

在調(diào)用sendNotification()else 條件之前,您將 bundle 置于不同的intent,而不是notifyIntent。在 else 中更改您的代碼,如下所示


else {

    // TODO: 10-10-2018 tapping on notification does nothing!!

    Log.d(TAG, "onHandleIntent(): Sending success notification.");

    String body = "Parsing complete for the url: " + url;

    Intent notifyIntent = new Intent(getApplicationContext(), ListSongsActivity.class);

    notifyIntent.putExtra(Constants.MUSIC_SITE, siteName);

    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    Bundle bundle = new Bundle();

    bundle.putParcelable(Constants.PARSED_ARTIST_INFO, artistInfo);

    notifyIntent.putExtras(bundle);

    CommonUtils.sendNotification(getApplicationContext(), Constants.LIST_SONGS_NOTIFICATION_TITLE

                            , body, Constants.LIST_SONGS_NOTIFICATION_CHANNEL_ID, notifyIntent,

                            Constants.LIST_SONGS_NOTIFICATION_ID, R.drawable.ic_launcher_background);

   }


查看完整回答
反對(duì) 回復(fù) 2021-11-11
?
幕布斯6054654

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超7個(gè)贊

也許您正在創(chuàng)建的待處理意圖比應(yīng)用程序中的要多。在這種情況下,您應(yīng)該使用,

PendingIntent.FLAG_CANCEL_CURRENT

從頭開始創(chuàng)建 Intent 并擴(kuò)充您的包


查看完整回答
反對(duì) 回復(fù) 2021-11-11
  • 2 回答
  • 0 關(guān)注
  • 172 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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