I have two problems regarding Android Services.
First, I would like to know which is less computationally expensive? Threads or Services?
Secondly, In my main android application I have tried to trigger 2 services:
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(ComponentName
.unflattenFromString("com.mrlite.service1"));
intent.addCategory("android.intent.category.LAUNCHER");
startService(intent);
intent.setComponent(ComponentName
.unflattenFromString("com.mrlite.service2"));
intent.addCategory("android.intent.category.LAUNCHER");
startService(intent);
Service1:
package com.mrlite.service1;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class Service1Activity extends Service {
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
super.onCreate();
//Intent intent = new Intent("android.intent.action.MAIN");
//String value = getIntent().getExtras().getString("1")
Log.e(getClass().getSimpleName(), "Service 1 Started");
}
@Override
public void onDestroy()
{
super.onDestroy();
Log.e(getClass().getSimpleName(), "Service 1 Destroyed");
}
}
Service 2:
package com.mrlite.service2;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class Service2Activity extends Service {
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
super.onCreate();
// Intent intent = new Intent("android.intent.action.MAIN");
// String value = getIntent().getExtras().getString("1")
Log.e("Service 2", "Service 2 Started");
}
@Override
public void onDestroy() {
super.onDestroy();
Log.e("Service 2", "Service 2 Destroyed");
}
}
Whenever I try to execute this code, only service 1 is called. Service 2 is never called.
How to trigger 2 services simultaneously?