Android RuntimeException: hizmet oluşturmak için Açılamıyor | Netgez.com
SORU
17 ÅžUBAT 2011, PERÅžEMBE


Android RuntimeException: hizmet oluşturmak için Açılamıyor

İntentService uzatacaktır Dersim uygulanan çok ayrı bir konu (UI Thread) üzerinde çalışan bir servis oluşturmak istiyorum. Ama hiçbir şans yok. İşte kod.

public class MyService extends IntentService {

    public MyService(String name) {
        super(name);
        // TODO Auto-generated constructor stub
    }

    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();
        Log.e("Service Example", "Service Started.. ");
        // pushBackground();

    }

    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        Log.e("Service Example", "Service Destroyed.. ");
    }

    @Override
    protected void onHandleIntent(Intent arg0) {
        // TODO Auto-generated method stub
        for (long i = 0; i <= 1000000; i  ) {
            Log.e("Service Example", " "   i);
            try {
                Thread.sleep(700);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}

Etkinlik Düğmeye bir tıklama olarak hizmet Tüketimi

public void onclick(View view) {
Intent svc = new Intent(this, MyService.class);
    startService(svc);
}

CEVAP
17 ÅžUBAT 2011, PERÅžEMBE


Beton uygulamanız uzatmak soyut İntentService sınıf public IntentService (String name) süper yapıcı çağrılar için varsayılan bir kurucu bildirmek için:

public MyService () {
  super("MyServerOrWhatever");
}

Eğer süper uygulama sizin için ne beklediğimi () uyarsa onStartCommand üzerine yazmak zorunda değilsiniz.

Mevcut durumda (ºÅŸlatılamadı hizmet...) - her zaman soru bu koymak için buna deÄŸer bir istisna almalısınız.

Bunu PaylaÅŸ:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Bennythecoder

    Bennythecode

    25 Mart 2008
  • Dion Coulls

    Dion Coulls

    16 AÄžUSTOS 2006
  • Kat Krazy

    Kat Krazy

    12 Kasım 2010