2013-03-07 62 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以及如何调用任务完成。

相关问题