shshnk
shshnk

Reputation: 1691

Service in a global process in not getting created

I am creating a service and there will be multiple applications talking to the service. So I want the service to run in a global process i.e. process is not private to any application. Here are the contents of my manifest file.

<?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>

the process attribute under service will create a global process. the problem is that when I try to start this service from activity on a button click then onCreate method in service in not getting called. Here is the code that executes on button click

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());
}

What am I missing here? Thanks!

Upvotes: 1

Views: 485

Answers (1)

shshnk
shshnk

Reputation: 1691

It was a stupid mistake. The service was getting created properly. I was checking the log in onCreate method but the logs were filtered to be shown only from selected application. Since the service was running in a separate process the logs from service were not appearing in the logcat. I just changed needed to change the filter. Putting a screenshot here in case it helps anyone. enter image description here

Upvotes: 1

Related Questions