Op Kaushik
Op Kaushik

Reputation: 140

Android Service Running as a separate process

I have a service Class in android. Is it be possible for a Service to run as a separate process than an application just for receiving SMS and enqueue them in a queue after that an application reads SMS from this Queue.

Is it possible to launch a separate service?

I have tag the source code of SmsService class below

public class SmsService extends Service {

private SMSReceiver mSMSreceiver;
private IntentFilter mIntentFilter;

@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    return null;
}
public SmsService(){
    /*dba = new DataBaseAdapter(this);*/
    mSMSreceiver = new SMSReceiver();
}
@Override
public void onCreate(){
    super.onCreate();       

    mIntentFilter = new IntentFilter();
    mIntentFilter.addAction(ConstantClass.SMS_RECEIVED);
    registerReceiver(mSMSreceiver,mIntentFilter);
}
@Override 
public int onStartCommand(Intent intent , int flags, int type){
    return START_STICKY;
}

@Override 
public void onDestroy(){
    super.onDestroy();
    //unregisterReceiver(mSMSreceiver);

}

Upvotes: 2

Views: 733

Answers (1)

waqaslam
waqaslam

Reputation: 68177

To enroll your service in a different process, you need to define android:process attribute when defining your service in AndroidManifest.xml

For example:

<service android:process=":kaushik" />

This will run your service in a new process called kaushik.

Upvotes: 2

Related Questions