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 ,
I have created a service , i want to read data fro it in multiple activities how i can do.
anyone please provide me an example or toturials

thanks

following is the code of my service :
public class HandleServer extends Service {

	private Server ser=null;
	public String IpAddress=null;
	public int port=0;
	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		
		try {
			Toast.makeText(this, "Closing", Toast.LENGTH_LONG).show();
			//ser.Close();
			Toast.makeText(this, "Closed", Toast.LENGTH_LONG).show();
			super.onDestroy();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			Toast.makeText(this, "Close error :" + e.getMessage(), Toast.LENGTH_LONG).show();
		}
	}

	@Override
	public void onStart(Intent intent, int startId) {
		
		// TODO Auto-generated method stub
		Toast.makeText(this, "starting", Toast.LENGTH_SHORT).show();
		
		try{
			ser = new Server();
			IpAddress= ser.IpAddress();
			port =ser.Port();
			ser.Start();
			//IPAddress.Clients(this, findViewById(R.id.hello_world));
		}
		catch(Exception ex){
			//((TextView)findViewById(R.id.txtStatus)).setText(ex.getMessage());
			Toast.makeText(this, ex.getMessage(), Toast.LENGTH_SHORT).show();
		}
		
		
		
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		// TODO Auto-generated method stub
		return super.onStartCommand(intent, flags, startId);
	}


}
Posted
Updated 12-May-13 20:27pm
v2
Comments
Sudhakar Shinde 13-May-13 1:47am    
What is the error you are facing in the code given by you?
shanalikhan 13-May-13 1:54am    
i have created a service but i want to get information from it in multipe activities , how i can transform the service wat ia the required code allows me to get information from it or calls its method in multiple activities

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