UPDATED:
谢谢各位的帮助。但是, finally, 我发现是我的手机(MX4 PRO)的问题。
换了其他手机和用emulator之后logcat恢复正常。
但是我并没有搞明白手机哪里出问题了。
public class TestService extends Service {
private static final String TAG = "TestService";
private TestBinder binder;
public TestService() {
binder = new TestBinder();
}
@Override
public void onCreate() {
super.onCreate();
Log.v(TAG, "onCreate()");
}
@Override
public IBinder onBind(Intent intent) {
Log.v(TAG, "onBind()");
return binder;
}
public class TestBinder extends Binder {
public void foo(){
Log.v(TAG, "TestBinder.foo()");
}
}
}
运行后看不到任何以“TestService”为 TAG 的日志输出。
搜索“TestService”后只看到下面这两句:
12-30 15:59:22.319 2887-3279/? W/ActivityManager: Scheduling restart of crashed service me.imlc.test/.service.TestService in 1000ms
12-30 15:59:22.319 2887-3279/? I/ActivityManager: Force stopping service ServiceRecord{1b7cc5fd u0 me.imlc.test/.service.TestService}
但是单步调试却能跟着Binder进入到 foo()语句中。
以及,系统的应用管理中依旧能看到TestService还在运行。
请问如何解决这个问题,没有logcat很难追踪程序逻辑~
看起来你的Service存在异常,被force stop了