У меня такая же проблема с флагами возвращает 0, и при убивании процесса сервиса он не восстанавливается. Помогите,пожалуйста,мучаюсь 2 дня уже. Сервис не вос [syntax=java]package com.example.les94;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import java.util.concurrent.TimeUnit;
public class MyService extends Service {
final String LOG_TAG = "myLogs";
public void onCreate() {
super.onCreate();
Log.d(LOG_TAG, "MyService onCreate");
}
public void onDestroy() {
super.onDestroy();
Log.d(LOG_TAG, "MyService onDestroy");
}
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(LOG_TAG, "MyService onStartCommand,name = "+intent.getStringExtra("name"));
readFlags(flags);
MyRun mr = new MyRun(startId);
new Thread(mr).start();
return START_STICKY;
}
public IBinder onBind(Intent arg0) {
return null;
}
void readFlags(int flags) {
switch (flags) {
case START_FLAG_REDELIVERY:
Log.d(LOG_TAG, "START_FLAG_REDELIVERY");
break;
case START_FLAG_RETRY:
Log.d(LOG_TAG, "START_FLAG_RETRY");
break;
case 0:
Log.d(LOG_TAG, "0");
break;
default:
Log.d(LOG_TAG, "readFlags: ERROR. Unexpected flag returned: " + flags);
}
}
class MyRun implements Runnable {
int startId;
public MyRun(int startId) {
this.startId = startId;
Log.d(LOG_TAG, "MyRun#" + startId + " create");
}
public void run() {
Log.d(LOG_TAG, "MyRun#" + startId + " start");
try {
TimeUnit.SECONDS.sleep(15);
} catch (InterruptedException e) {
e.printStackTrace();
}
stop();
}
void stop() {
Log.d(LOG_TAG, "MyRun#" + startId + " end, stopSelfResult("
+ startId + ") = " + stopSelfResult(startId));
}
}
}
[/syntax]
А вот манифест [syntax=xml]<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="
http://schemas.android.com/apk/res/android"
package="com.example.les94" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyService"
android:enabled="true"
android:exported="true"
android:process=":myService">
<intent-filter>
<action android:name="com.example.les94.MyService"/>
</intent-filter>
</service>
</application>
</manifest>
[/syntax]
А вот лог:
12-30 21:39:24.289 22045-22045/? D/myLogs: MyService onCreate
12-30 21:39:24.290 22045-22045/? D/myLogs: MyService onStartCommand,name = value
12-30 21:39:24.290 22045-22045/? D/myLogs: 0
12-30 21:39:24.291 22045-22045/? D/myLogs: MyRun#1 create
12-30 21:39:24.293 22045-22058/? D/myLogs: MyRun#1 start
12-30 21:39:25.012 22045-22045/? D/myLogs: MyService onStartCommand,name = value
12-30 21:39:25.013 22045-22045/? D/myLogs: 0
12-30 21:39:25.013 22045-22045/? D/myLogs: MyRun#2 create
12-30 21:39:25.019 22045-22059/? D/myLogs: MyRun#2 start
12-30 21:39:39.294 22045-22058/? D/myLogs: MyRun#1 end, stopSelfResult(1) = false
12-30 21:39:40.021 22045-22045/? D/myLogs: MyService onDestroy
12-30 21:39:40.024 22045-22059/? D/myLogs: MyRun#2 end, stopSelfResult(2) = true
То есть метод onStartCommand всегда выдает флаг 0