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

  • JamesAtiPhone

    JamesAtiPhon

    16 EYLÜL 2010
  • Julian Smith

    Julian Smith

    31 EKİM 2006
  • Attempts at least

    Attempts at

    1 Ocak 2007