SORU
15 Mart 2013, Cuma


Nasıl Otto olay otobüs ile etkinliğe hizmetinden olay göndermek için?

Basit BusProvider.getInstance().post() istisna main threadgetirin. Nasıl Otto olay otobüs ile etkinliğe hizmetinden olay göndermek için?

CEVAP
15 Mart 2013, Cuma


Herhangi bir iş parçacığı (ana veya arka plan) post ve ana iş parçacığı almak için, gibi bir şey deneyin

public class MainThreadBus extends Bus {
  private final Handler mHandler = new Handler(Looper.getMainLooper());

  @Override
  public void post(final Object event) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
      super.post(event);
    } else {
      mHandler.post(new Runnable() {
        @Override
        public void run() {
          MainThreadBus.super.post(event);
        }
      });
    }
  }

Not: kredi Jake Wharton gider ve "" https://github.com/square/otto/issues/38 genel yaklaşım. pommedeterresaute Ben sadece kapsayıcı bir sınıf yerine bir alt sınıf ile gerçekleştirdi.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • bigky226

    bigky226

    11 HAZİRAN 2006
  • Flash CS6 Video Tutorials for Beginners (Actionscript 3 Gaming)

    Flash CS6 Vi

    14 EYLÜL 2012
  • TheJoeycool2010

    TheJoeycool2

    12 Temmuz 2010