simple service

Put your problem here if it does not fit any of the other categories.

simple service

Postby aglesteban » Fri Nov 21, 2008 5:19 pm

I would like to create a very simple service for android. I have an android activity that reads a string and I would like to call a service that changes this string, and show the new string. That's it. I'm just learning about how to create services. Thanks!
aglesteban
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Nov 21, 2008 5:11 pm

Top

code of my activity

Postby aglesteban » Fri Nov 21, 2008 5:25 pm

This is the code of my activity. How can be the code of my service?

package android.com.conectarBot;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.*;

public class ConectarBot extends Activity {
// Definimos los atributos que har�n referencia a los
// dos TextEdit.
private EditText campoTexto;
private EditText campoRespuesta;
private static final int ENVIAR = Menu.FIRST;
private static final int SALIR = Menu.FIRST + 1;

// Sobreescribimos el m�todo que genera el men� de la Actividad
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, ENVIAR, R.string.enviar, null);
//menu.add(0, PESETAS_EN_EUROS, R.string.pesetas2euros, null);
menu.add(0, SALIR, R.string.salir, null);

return true;
}


public void f_enviar()
{
String respuesta="";

//This was the part I want to change, instead of calling the function f from the class a, I wanna do it with a service
jar.Clase a=new jar.Clase();
respuesta=a.f(campoTexto.getText().toString());



campoRespuesta.setText(" "+respuesta);
}

// Sale de la actividad
public void f_salir()
{
setResult(RESULT_OK);
finish();
}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

// Establecemos las referencias de los EditText
campoTexto = (EditText) findViewById(R.id.entrada);
campoRespuesta = (EditText) findViewById(R.id.salida);

// Establecemos las referencias de los Button
Button enviar = (Button) findViewById(R.id.enviar);

Button salir = (Button) findViewById(R.id.salir);

// A�adimos el c�digo que manejar� el clic en cada bot�n
enviar.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
f_enviar();
}
});

salir.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
f_salir();
}
});
}
}
aglesteban
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Nov 21, 2008 5:11 pm

where can I find tutorial about doing a service for android?

Postby aglesteban » Fri Nov 21, 2008 6:02 pm

I really don't know exactly how to do a service, so that's why I'm trying to do a simple one, if somebody knows where can I find a good tutorial to create services for android, it will be great. Thank you.
aglesteban
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Nov 21, 2008 5:11 pm

Postby richard.puckett » Fri Nov 21, 2008 8:03 pm

Take a look at com.example.android.apis.app.RemoteService in the ApiDemos sample
Image
richard.puckett
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Dec 27, 2007 2:37 am
Location: Seattle, WA

Thanks

Postby aglesteban » Fri Nov 21, 2008 10:12 pm

Thank you, it seems so helpful. I'm gonna take a look on it.
aglesteban
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Nov 21, 2008 5:11 pm

Service

Postby Txorl » Sat Nov 22, 2008 10:57 am

I am as well having problems with Services.

Example:

public class myService extends Service{
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
}

@Override
public void onDestroy() {
}
}

When I now try to start the Service from an activity
startService(new Intent(mainCaller.this, myService.class));
I get the warning:
Unable to start service Intent { comp={d.d/d.d.myService} }: not found

Why cant he find my Service?

Thanks in advance
Txorl
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Sep 17, 2008 3:12 pm

Top

onCreate or onStart?

Postby aglesteban » Sat Nov 22, 2008 4:39 pm

in my simple application there is a text, I wanna click a button, and call my service that is gonna change this text and send it back.
I don't know exactly if I should put oncreate or onstart, I don't know the difference
What I wanna do is to send a string to the service, change it in the service and send it back to the activity that is gonna show the result.
Thanks a lot for helping me.
aglesteban
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Nov 21, 2008 5:11 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 16 guests