Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi ,
Im unable to bind the service to second activity. I have bind and started the service from one activity but when i go to other acitivity i want to bind that activity also. but there are errors. please have a look :



first activity :

C#
protected void onPause() {
        Toast.makeText(this, "service unbinded", Toast.LENGTH_LONG).show();
        unbindService(myconn);

        super.onPause();
    }


C#
public void OnShowDevices(View v){
        //unbindService(myconn);
        Intent in = new Intent(this , ConnectedDevice.class);
        startActivity(in);
    }

C#
protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        Intent intq = new Intent(this ,Server.class);
        startService(intq);
        bindService(intq, myconn, Context.BIND_AUTO_CREATE);

        try{

        }
        catch(Exception ex){
            ((TextView)findViewById(R.id.txtStatus)).setText(ex.getMessage());
        }



    }






while the second activity :
C#
try{
            Toast.makeText(this, "Starting", Toast.LENGTH_SHORT).show();
            Intent intq = new Intent(this ,Server.class);
            //startService(intq);
            bindService(intq, myconn, Context.BIND_AUTO_CREATE);
             //GridView gridview = (GridView) findViewById(R.id.lstDevices);
               // gridview.setAdapter(new DeviceAdaptor(this, ser.Clients()));

        }
        catch(Exception ex)
        {
            Toast.makeText(this, ex.getMessage(), Toast.LENGTH_SHORT).show();
        }
Posted
Comments
TorstenH. 21-May-13 3:07am    
Which errors are there? Please tell us what you're facing exactly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900