how to start service in android without an activity
android, android-activity, broadcastreceiver, service
Solution
Start your Service from SmsReceiver as:
public class SmsReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals("android.provider.Telephony.SMS_RECEIVED")){
//action for sms received
// start service here
Intent intent=new Intent(context,Your_Service.class);
context.startService(intent);
}
else {
}
}
}
and make sure you have registered your service in `AndroidManifest.xml` as :
<service android:name="com.xxx.xx.Your_Service" />
Problem
i am beginner at android. I have two class, and first class is ``` public class SmsReceiver extends BroadcastReceiver{} ``` And the second class is ``` public class SMS extends Activity{} ``` All I want to do that : when I get an SMS, start activity and do something. But i want to use "service" instead of "activity". I mean when application start, then start service without activity. is this possible ?