startservice不适用于具有process属性的服务

时间:2017-09-06 11:27:08

标签: android multithreading service

我有一个非常简单的服务,试图在一个单独的进程中运行它,但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属性的服务?

1 个答案:

答案 0 :(得分:1)

确保过滤logcat中的日志以获取正确的进程。由于服务在不同的进程中运行,因此默认情况下并不总是看到它们。