Я перепробовал все решения в стеке, но ничего не помогло для этой проблемы
Файл манифеста
<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);
}
}