在全球流程中服务而不是被创造

Service in a global process in not getting created

我正在创建一个服务,将有多个应用程序与该服务通信。所以我希望服务在全局进程中 运行 即进程不是任何应用程序私有的。 这是我的清单文件的内容。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.username.servicedemo" >

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service
        android:name="com.example.username.servicedemo.FirstService"
        android:process="com.example.username.servicedemo.remote"
        android:enabled="true"
        android:exported="true" >
    </service>
</application>

service 下的 process 属性将创建一个全局进程。 问题是,当我尝试在按钮上从 activity 启动此 service 时,单击然后 service 中的 onCreate 方法未被调用。这是在单击按钮时执行的代码

public void startService (View view) {

    int id = android.os.Process.myPid();
    Log.i("MYTAG", " process id activity" + Integer.toString(id)

    );
    Intent intent = new Intent(this,FirstService.class);
    intent.putExtra("key","1234");
    ComponentName componentName = this.startService(intent);
    Log.i("MYTAG",componentName.toString());
}

我在这里错过了什么?谢谢!

这是一个愚蠢的错误。 service 已正确创建。我正在检查登录 onCreate 方法,但日志被过滤为仅从选定的应用程序中显示。由于 service 是 运行 在一个单独的进程中,来自 service 的日志没有出现在 logcat 中。 我只是改变了需要改变过滤器。在这里放一个屏幕截图以防它对任何人有帮助。