【发布时间】:2017-09-06 11:27:07
【问题描述】:
我有一个非常简单的服务,试图在单独的进程中运行它,但是startService() 方法根本没有效果,除非我让它在同一个进程中运行[从清单中删除了进程属性]!
服务:
public class RemoteService extends Service {
/** Called when the service is being created. */
@Override
public void onCreate() {
Log.v("RemoteService", "Service:onCreate===> called");
}
/** The service is starting, due to a call to startService() */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.v("RemoteService", "Service:onStartCommand===> called");
return START_STICKY;
}
/** A client is binding to the service with bindService() */
@Override
public IBinder onBind(Intent intent) {
Log.v("RemoteService", "Service:onBind===> called");
return null;
}
/** Called when a client is binding to the service with bindService()*/
@Override
public void onRebind(Intent intent) {
Log.v("RemoteService", "Service:onRebind===> called");
}
/** Called when The service is no longer used and is being destroyed */
@Override
public void onDestroy() {
Log.v("RemoteService", "Service:onDestroy===> called");
}
}
清单:
<service
android:name=".RemoteService"
android:enabled="true"
android:exported="false"
android:process=":worker"></service>
活动:
startService(new Intent(this, RemoteService.class));
那么,如何启动具有process 属性的服务呢?
【问题讨论】:
-
你怎么知道它不起作用
-
@TimCastelijns 日志永远不会出现,尤其是 onCreate 日志
-
您是否为正确的进程过滤日志?
-
@TimCastelijns 谢谢!我没有看到日志,过滤器隐藏了它们!它工作正常
标签: android multithreading service