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

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

活動(dòng)/片段暫停時(shí)如何處理處理程序消息

活動(dòng)/片段暫停時(shí)如何處理處理程序消息

慕運(yùn)維8079593 2019-10-23 14:21:32
我的其他帖子略有變化基本上我有一個(gè)消息Handler在我的Fragment接收一串可導(dǎo)致對(duì)話消息被解雇或示出。當(dāng)應(yīng)用程序進(jìn)入后臺(tái)時(shí),我得到一個(gè)提示,onPause但仍然如我所愿地通過(guò)我的消息。但是,因?yàn)槲沂褂玫氖瞧?,所以我不能只關(guān)閉并顯示對(duì)話框,因?yàn)檫@將導(dǎo)致IllegalStateException。我不能只是解雇或取消允許狀態(tài)丟失。鑒于我有一個(gè)問(wèn)題,Handler我想知道是否有關(guān)于在暫停狀態(tài)下如何處理消息的推薦方法。我正在考慮的一種可能的解決方案是記錄暫停時(shí)通過(guò)的消息并在上播放它們onResume。這有點(diǎn)不能令人滿意,我想框架中必須有一些東西可以更優(yōu)雅地處理它。
查看完整描述

3 回答

?
蠱毒傳說(shuō)

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

quickdraw出色的PauseHandler的一個(gè)稍微簡(jiǎn)單的版本是


/**

 * Message Handler class that supports buffering up of messages when the activity is paused i.e. in the background.

 */

public abstract class PauseHandler extends Handler {


    /**

     * Message Queue Buffer

     */

    private final List<Message> messageQueueBuffer = Collections.synchronizedList(new ArrayList<Message>());


    /**

     * Flag indicating the pause state

     */

    private Activity activity;


    /**

     * Resume the handler.

     */

    public final synchronized void resume(Activity activity) {

        this.activity = activity;


        while (messageQueueBuffer.size() > 0) {

            final Message msg = messageQueueBuffer.get(0);

            messageQueueBuffer.remove(0);

            sendMessage(msg);

        }

    }


    /**

     * Pause the handler.

     */

    public final synchronized void pause() {

        activity = null;

    }


    /**

     * Store the message if we have been paused, otherwise handle it now.

     *

     * @param msg   Message to handle.

     */

    @Override

    public final synchronized void handleMessage(Message msg) {

        if (activity == null) {

            final Message msgCopy = new Message();

            msgCopy.copyFrom(msg);

            messageQueueBuffer.add(msgCopy);

        } else {

            processMessage(activity, msg);

        }

    }


    /**

     * Notification message to be processed. This will either be directly from

     * handleMessage or played back from a saved message when the activity was

     * paused.

     *

     * @param activity  Activity owning this Handler that isn't currently paused.

     * @param message   Message to be handled

     */

    protected abstract void processMessage(Activity activity, Message message);


}

它確實(shí)假定您始終要存儲(chǔ)脫機(jī)消息以進(jìn)行重播。并提供“活動(dòng)”作為輸入,#processMessages因此您無(wú)需在子類中對(duì)其進(jìn)行管理。


查看完整回答
反對(duì) 回復(fù) 2019-10-23
  • 3 回答
  • 0 關(guān)注
  • 529 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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