清单文件中服务声明的类或接口预期错误

时间:2019-05-29 10:47:21

标签: android android-studio android-service

我已经尝试了所有堆栈上的解决方案,但是没有任何解决方案

清单文件

  <application
   android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="Screen"
    android:theme="@style/AppTheme">
    <service
        android:name=".LocalService"
        android:enabled="true"
        android:exported="true"></service>

    <activity
        android:name=".MainActivity"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait"></activity>
    </application>

MainActivity调用服务的地方

    startService(new Intent(this,LocalService.class));

服务等级

     public class LocalService extends Service {
      public LocalService() {
      }

@Override
public IBinder onBind(Intent intent) {
    // TODO: Return the communication channel to the service.
    throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return super.onStartCommand(intent, flags, startId);
}
 }  

1 个答案:

答案 0 :(得分:1)

删除代码中的'

<application
   android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="Screen"
    android:theme="@style/AppTheme">
    <service
        android:name=".LocalService"
        android:enabled="true"
        android:exported="true"></service>

    <activity
        android:name=".MainActivity"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait"></activity>
    </application>