veo el siguiente error en DDMS al intentar utilizar una casilla en mi MyActivity" actividad para iniciar un servicio llamado 'MyService':"No se puede iniciar Intención servicio" error al iniciar el servicio de una actividad en Android
W/ActivityManager( 73): Unable to start service Intent { cmp=com.example.android.myprogram/.MyService }: not found
que utiliza el tutorial http://developer.android.com/resources/tutorials/views/hello-formstuff.html y añade el código proporcionado al final de mi método onCreate(). tengo las clases especificadas por separado en MyActivity.java y MyService.java.
package com.example.android.myprogram;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
public class MyActivity extends Activity {
private static final String TAG = "MyActivity";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
checkbox.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks, depending on whether it's now checked
if (((CheckBox) v).isChecked()) {
// TODO: Add code to START the service
Log.d(TAG, "startService from checkbox");
startService(new Intent(MyActivity.this, MyService.class));
} else {
// TODO: Add code to STOP the service
Log.d(TAG, "stopService from checkbox");
stopService(new Intent(MyActivity.this, MyService.class));
}
}
});
}
}
mi archivo de manifiesto tiene el siguiente en el que también he probado el completo espacio de nombres, nombre corto, uso de un filtro de intención por otra búsqueda, etc. No estoy diciendo que lo que está allí es correcto. Lo dejé en un punto de parada.
<service android:name=".MyService">
<intent-filter><action android:name="com.example.android.myprogram.MyService"></action>
</intent-filter>
</service>
Y por último, mi servicio que he decidido a romper a su mínima expresión:
package com.example.android.myprogram;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class MyService extends Service {
private static final String TAG = "MyService";
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
Log.d(TAG, "onCreate");
//code to execute when the service is first created
}
@Override
public void onDestroy() {
Log.d(TAG, "onDestroy");
//code to execute when the service is shutting down
}
@Override
public void onStart(Intent intent, int startid) {
Log.d(TAG, "onStart");
//code to execute when the service is starting up
}
}
Estoy muy, muy, muy nuevo en la programación Java/Android y programación en general (pero aprendiendo), así que estoy seguro de que esto es un error del usuario y, probablemente, de sentido común para todos los demás. Cualquier sugerencia seria genial.
Podría pegar el código del servicio? – Cristian
Cristian, gracias por responder. Código ha sido agregado. Pregunta: ¿Debería poder usar esto y obtener un resultado exitoso? http://android.kgmoney.net/2010/05/08/creating-a-simple-android-service-for-background-processing/. No está funcionando tampoco. – capitalf