java - 为什么我的情况下服务没有启动?

标签 java android

我对 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/

相关文章:

android - 测试 RxJava 无限间隔

android - 如何在 Android Studio 3.0 中实现带有文本的开关

android - 蓝牙 BLE 的 UUID 和 MAC 地址

android - 放大时显示相同的图 block 而不是从服务器获取它们

android - OKHTTP RequestBody错误无法访问ByteString

java - 文本和字符串有什么区别?

java - JSF2 EL 未显示在组件 ID 中

java - OAuth2 : How to generate client id and client secret?

java - 构造函数的控制松散

java - 创建并打印 HashMap<String, Integer>