He creado un servicio que se llama desde la actividad principal y le paso una variable simple para acceder y brindar por la pantalla desde el interior del servicio. Parece que no puedo encontrar el código correcto para acceder a la variable desde el interior del servicio. Cualquier ayuda sería muy apreciada. Gracias.Android: Las variables de acceso pasaron al servicio
Actividad Principal llamando al servicio desde el interior de un clic de botón oyente:
@Override
public void onClick(View v) {
Intent eSendIntent = new Intent(getApplicationContext(), eSendService.class);
eSendIntent.putExtra("extraData", "somedata");
startService(eSendIntent);
}
eSendService código de clase de servicio:
public class eSendService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
// This is the code that I am struggling with. Not sure how to access the
// variable that was set in the intent. Please advise.
// The below code gives the following error in eclipse:
// The method getIntent() is undefined for the type eSendService
Bundle extras = getIntent().getExtras();
}
}
Una vez más, gracias por todos y cada uno ayuda. Simplemente no puedo encontrar un ejemplo simple que me muestre cómo hacer esto. Gracias.
Hi E Z Hart. Lo intenté después del método super.onCreate() sin cambios. Eclipse está subrayando "getIntent()" y cuando lo paso sobre él obtengo este error "El método getIntent() no está definido para el tipo eSendService". Gracias por tu ayuda. – RayJamesFun