我对 Android 非常陌生,我正在尝试了解该服务。
我的 list 文件看起来:
<!--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);
}
}
我的应用程序正在执行,没有任何错误。但没有创建任何服务!我哪里出错了?
提前致谢。
最佳答案
在 list 中使用此权限
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
关于java - 为什么我的情况下服务没有启动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15267660/