startService from class that does not extend Activity

I have created a class that extends IntentService, and I would like to start the service from a class that is not an Activity, therefore, I do not have access to a Context object. I could not find an example of this in the documentation or the web. Is it possible ?

  • Get the URI of an image stored in drawable
  • How to delete app cache for all apps in Android M?
  • Android MVP - How to communicate between activity presenter and fragment presenter
  • How to make the linearlayout in scrollview to fill the whole area
  • Android: View.getTag/setTag and IllegalArgumentException
  • Saving the API Key in
  • Related posts:

    ViewPager in a ListView - how to lock the scrolling axis?
    From whence cometh Enum.values()?
    how to navigate to error lines in Android Studio by shortcut?
    How to customize listview using baseadapter
    Debugging Android Apps on Dell Venue 7 using Eclipse
    Proguard retrace output confusion
  • Android - MultipartEntity and dependencies
  • How to set the color of a TextView in Android?
  • Google Play developer console: beta test paid apps for free?
  • Custom AsyncTaskLoader, loadinBackground not called after 5 attempts
  • From Notification: AlertDialog without UI
  • Check whether database is empty
  • 2 Solutions collect form web for “startService from class that does not extend Activity”

    You will need to pass current Activity context to non Activity class for starting service from non-activity class as:

    public class NonActivity {
    public Context context;
    public NonActivity(Context context)
    public void startServicefromNonActivity(){
       Intent intent=new Intent(context,yourIntentService.class);

    and pass current context as:

    public class AppActivity extends Activity {
        NonActivity nonactiityobj;
        public void onCreate(Bundle savedInstanceState) {
                     nonactiityobj=new NonActivity(CuttentActivity.this);
                     //start service here

    Use this code Start and Stop Service

    public class MyService {
    Context context ;
    public MyService(Context cont) {
        this.context = context ;
    public void StartMyService()
        Intent i = new Intent(context,YourService.class);
    public void StopMyService()
        Intent i = new Intent(context,YourService.class);

    This just create object of this class

      MyService mySevice ;
      public void onCreate(Bundle savedInstanceState) {
      myService = new MyService(this);
      //For Startting Service
      //For Stopping Service
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.