Error: constructor de intenciones indefinidas al iniciar el servicio en android

Estoy intentando comenzar el servicio en la actividad. Pero muestra error como "el constructor Intent (SampleService, MyService) es undefined"

MyService.java

public class MyService extends Service { @Override public IBinder onBind(Intent intent) { return null; } public static boolean isInstanceCreated() { return instance != null; } @Override public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); instance = this; } @Override public void onDestroy() { Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show(); Log.d(TAG, "onDestroy"); instance = null; } @Override public void onStart(Intent intent, int startid) { Toast.makeText(getBaseContext(), "Service started",Toast.LENGTH_SHORT).show(); } } 

Inicio del servicio desde SampleService.java

  public class SampleService extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.grid_activity); Intent myintent =new Intent(SampleService.this,MyService.this);//Error show here.. startService(myintent); } } 

Servicio inicializado en archivo de manifiesto.

  <service android:enabled="true" android:name="com.MyApp.MyService" /> 

Ayúdame a resolver el error.

no es Service.this tienes que pasar clase así cambiar así.

 Intent myintent =new Intent(SampleService.this,MyService.Class); 

Cambia esto

  Intent myintent =new Intent(SampleService.this,MyService.this); 

a

  Intent myintent =new Intent(SampleService.this,MyService.Class); // first param is a context second param is a class in your case a MyServiceClass 

Observe los constructores públicos en que no tiene un constructor como Intent(SampleService, MyService) . Tiene Intent(SampleService, MyService) erróneos para el constructor de intenciones.

http://developer.android.com/reference/android/content/Intent.html

 public Intent (Context packageContext, Class<?> cls) Added in API level 1 Create an intent for a specific component. All other fields (action, data, type, class) are null, though they can be modified later with explicit calls. This provides a convenient way to create an intent that is intended to execute a hard-coded class name, rather than relying on the system to find an appropriate class for you; see setComponent(ComponentName) for more information on the repercussions of this. Parameters packageContext A Context of the application package implementing this class. cls The component class that is to be used for the intent. 
  • Integración de Google + en la vista web
  • Abrir archivo adjunto .txt de correo electrónico en la aplicación para Android
  • Propuesta de participación exitosa para android
  • Android startActivity () se estrelló
  • ¿Por qué estoy recibiendo el error "MyActivity no es una clase inclusiva?"
  • ¿Cómo saber qué aplicación fue seleccionada por Intent.createChooser?
  • Android.content.ActivityNotFoundException: Ninguna actividad encontrada para manejar Intent splash screen
  • Uso de Intent en una aplicación de Android para mostrar otra actividad
  • Intent.getExtras () devuelve siempre null
  • Android: lanzar aplicación desde el receptor de difusión
  • Prácticas recomendadas: agregar tu aplicación al menú de recursos compartidos de Android
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.