Hello guys, I start a thread with a simple counter from 1 to 1000. My
interface has Start and Stop functions.
I want to stop the counter but when I click on Stop my App is
returning the exception
 "java.lang.IllegalArgumentException: Service not registered ".

Anyone knows how to solve this problem.
I using the interface Runnable...

Thanks...

[Main Activity] - Not the entire code

public class ServiceConnectionMain extends Activity implements
ServiceConnection{



     //interface ServiceConnection
        final ServiceConnection conexao = this;

        //Iniciar servico
        Button btStart = (Button) findViewById(R.id.btnstart);
        btStart.setOnClickListener(new Button.OnClickListener(){
            public void onClick( View v ){

                //cria uma intent para a classe de servico
                Class classeServico = ServicoComConexao.class;
                Intent itService = new
Intent( ServiceConnectionMain.this, classeServico);

                bindService( itService, conexao,
Context.BIND_AUTO_CREATE );

                }
        });

        //Parar Servico
        Button btStop = (Button) findViewById(R.id.btnstop);
        btStop.setOnClickListener(new Button.OnClickListener(){
            public void onClick(View v){
                    unbindService( conexao );
                    mBound = false;
            }
        });
    }

    public void onServiceConnected(ComponentName className, IBinder
service) {
        // Recupera a interface para interagir com o serviÁo
        LocalBinder binder = (LocalBinder) service;
        contador = binder.getService();
    }

    public void onServiceDisconnected(ComponentName className) {
        contador = null;
    }
}


[Service with Thread] not entire code


public class ExemploServico extends Service implements Runnable {

    private static final String CATEGORIA = "exemplo";

    protected int count;
    private static final int MAX = 1000;
    private boolean ativo;

    public void run() {
        // TODO Auto-generated method stub
        ativo = true;
        while (ativo && count <= MAX){
            Log.i(CATEGORIA, "Contador está em: " + count);
            doThing();
            count++;
        }

    }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to