java - Suggestions for a multiple socket design (Android) -


i'm trying think of way implement app that:

-opens x amount of sockets (user specified)
-each socket can remain open lifetime of application , continues running in background
-creates multiple activities of same layout, each used display information received socket.

currently have implementation takes sends/receives 1 socket. service runs in background continue processing information socket, , sends activity. however, current train of thought leads me believe i'd need 1 service each socket open continue processing in background. i'm new android clarification great.

thanks

i implement single service manages socket connections. services defined in androidmanifest consequence can't run multiple services of same type, , can't create services @ runtime (by can't define new services @ runtime). you're stuck using single service. doesn't mean can't have multiple instances of class represent each connection server. in fact that's i'd recommend, instances won't android services.

its of same thing activities. can't create multiple instances of activity @ same time. android plays lots of tricks make appear way, in reality either same instance had last time, or 1 gone , here new one. but, @ 1 time there ever 1 instance of activity. you'll have make limitations, there own keep using tons of memory.

now, means activity displays chat session have flexible can parameterized session should displaying. can done intent parameter. example:

public void opensession( chatsession session ) {     intent intent = new intent( getcontext(), chatsessionactivity.class )          .putextra( chatsessionactivity.param_chat_session_id, session.getid() );     startactivity( intent ); } 

and that's how activity might navigate user chatsession picking list of chat sessions. in activity you'd @ intent passed oncreate(), , connect service, query service chatsession. you'll have have mechanism allow chatsessionactivity register , unregister service updates. through using broadcastreceivers, register listeners, messages, etc. there's whole host of options. example:

public void onserviceconnected() {    chatsession session = service.getsession( sessionid );    session.setchatlistener( ); }  public void onstart() {     if( service.isconnected() ) session.setchatlistener(this); }  public void onstop() {    session.setchatlistener( null ); } 

anyway, simple ideas on how structure program.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -