Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 启动完成时未启动服务_Android_Service_Broadcastreceiver - Fatal编程技术网

Android 启动完成时未启动服务

Android 启动完成时未启动服务,android,service,broadcastreceiver,Android,Service,Broadcastreceiver,我有一个服务,我想启动开机完成 启动时,会显示一条祝酒词 我的问题是,当设备启动时,toast会显示并卡在屏幕上,服务无法正确启动 但是,如果我试图通过活动启动服务,则服务启动良好,几秒钟后祝酒词就会消失 我的舱单: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tfl.extprotocolservice" android:versionCode="7"

我有一个服务,我想启动开机完成

启动时,会显示一条祝酒词

我的问题是,当设备启动时,toast会显示并卡在屏幕上,服务无法正确启动

但是,如果我试图通过活动启动服务,则服务启动良好,几秒钟后祝酒词就会消失

我的舱单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tfl.extprotocolservice"
    android:versionCode="7"
    android:versionName="1.6" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <receiver android:name="com.tfl.extprotocolservice.ExtProtocolBroadcastReceiver"
            android:enabled="true" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

        <service android:name=".ExtProtocolService" >
            <intent-filter>
                <action android:name="com.tfl.extprotocolservice.ISetIpPort" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.tfl.extprotocolservice.IExtMessage" />
            </intent-filter>
        </service>
 <!-- 
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="landscape" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 -->
    </application>

</manifest>

顺便说一句,清单中的活动被注释是因为我并不真的需要它,它只是测试从一个活动启动服务。

我尝试了
am broadcast-a android.intent.action.BOOT\u完成
,然后它重新启动设备

您可以试试


经过更多的研究,我认为是
fastboot模式
无法广播引导完成

您的服务正在过滤操作,但您的意图没有提供任何内容。 解决这个问题:

StartServiceIntent.setAction("com.tfl.extprotocolservice.IExtMessage");

如果您的应用程序没有活动,您的
广播接收器将永远不会被调用

安装应用程序时,它将以“停止状态”安装。处于“停止状态”的应用程序不会获得发送给它们的广播
Intent
s

为了使应用程序脱离“停止状态”,用户必须手动启动应用程序(至少一次)。为此,您必须向他提供一个
活动
,他可以使用该活动启动您的应用程序

一旦您的应用程序不再处于“停止状态”,Android将向其发送广播
Intent
s。也就是说,直到用户“强制停止”应用程序


如果用户“强制停止”您的应用程序,它将返回“停止状态”,不再获得广播
Intent
s。直到用户再次手动启动您的应用程序。

什么是fastboot模式?fastboot与此问题无关,fasboot甚至不会启动Android操作系统。您可能会将其与“快速启动”混淆。一些HTC设备可以启用“快速启动”功能,这更像是深度休眠,而不是真正的重新启动,因此不应该给出完全的启动意图。要恢复此操作,只需在receivers intent filter“”中添加此操作。如果首先从启动器启动应用程序,然后重新启动,会发生什么情况?重启会触发你的服务吗?@HappyCactus不幸的是不会。你去的地方还是一样!在Android 3.1中添加/更改了此行为:
StartServiceIntent.setAction("com.tfl.extprotocolservice.IExtMessage");