2013-03-07 26 views
2

我對Android非常陌生,我試圖瞭解這項服務。爲什麼服務不是從我的情況開始的?

我的清單文件如下:

<!--The invoice launcher service--> 
    <service android:process=":invoice_background" 
      android:name="InvoiceManagerService" 
      android:label="invoice_service" /> 

    <!--The receiver--> 
    <receiver android:name="InvoiceStartupReceiver" 
       android:process=":invoice_background"> 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     </intent-filter> 
    </receiver> 

我的服務是這樣的:

public class InvoiceManagerService extends Service { 

    public IBinder onBind(Intent intent) { 
     return null; 
    } 
} 

和我的接收機是這樣的:沒有任何錯誤得到執行

public class InvoiceStartupReceiver extends BroadcastReceiver { 

    public void onReceive(Context context, Intent intent) { 

     Intent invoiceService = new Intent(context, InvoiceManagerService.class); 
     context.startService(invoiceService); 


    } 
} 

我的應用程序。但沒有創建服務!我犯了什麼錯誤?

在此先感謝。

+0

1 /您是否有權接收boot_completed廣播? 2 /你重新啓動你的手機嗎? 3 /你可以在logcat中看到什麼? – njzk2 2013-03-07 09:51:56

+0

@ njzk2:我正在測試我的模擬器。而在logcat中,我沒有看到任何說我的服務已經啓動的日誌。 – batman 2013-03-07 09:55:01

回答

3

使用該許可清單中

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
+0

沒有幫助:/ – batman 2013-03-07 09:47:58

0

我因爲這句話,我建議你使用IntentService,而不是作爲Service的IntentService很新到Android

是容易得多使用。我爲另一個answer寫了一些基本代碼,其中該人想下載一個文件,然後通知活動發生了。它會告訴你正確使用IntentService以及如何調用任務完成。

相關問題