Search code examples
androidandroid-intentbroadcastreceiverandroid-serviceandroid-2.2-froyo

Can we start a user-defined service from the broadcast receiver?


I'm developing an application for mobiles and tablet in Android. I'm using Android 2.2

In broadcast receiver, we can put some simple process (small process/small running module code snippet). It is not suited for long running process/Long running module like gps location capturing,etc.

Can we start a service (user defined service - not a Android service) from the broadcast receiver?


Solution

  • Yes, you can start a service from BroadcastReceiver. You actually need Context to start a Service. For example:

    @Override
    public void onReceive(Context context, Intent intent) {
    
        Intent intent = new Intent(context, YourService.class);
        context.startService(intent);
    }