java - Android SignalR should be implemented as Service or IntentService? -


on android app, i'm implementing signalr connection (https://github.com/erizet/signala) connect hub server send requests , receive responses.

a sample of code follows:

signalaconnection = new com.zsoft.signala.connection(constants.gethuburl(), this, new longpollingtransport()) {     @override     public void onerror(exception exception)     {     }      @override     public void onmessage(string message)     {     }      @override     public void onstatechanged(statebase oldstate, statebase newstate)     {     } };  if (signalaconnection != null)     signalaconnection.start(); 

there's sending bit

signalaconnection.send(hubmessagejson, new sendcallback() {     public void onerror(exception ex)     {     }      public void onsent(charsequence message)     {     } }); 

the sending , receiving occur across activites, , responses sent @ random times regardless of activity, also, connection should opened long app running (even if app running in background) that's why wish implement signala connection background service

the question should implement as:

1 - service (http://developer.android.com/reference/android/app/service.html)

or

2 - intent service (http://developer.android.com/training/run-background-service/create-service.html)

keeping in mind need send strings service , response strings service.

i grateful if show me how implement kind of connection in code background service/intentservice.

thanks reading.

update:

please see demo activity made developer how implemented signala https://github.com/erizet/signala/blob/master/demo/src/com/zsoft/signalademo/demoactivity.java

the problem aquery (which know nothing about) being used in demo activity. aquery run in background time ? problem is, latest update on signala mentions following

i have changed transport. longpolling uses basic-http-client instead of aquery http communication. i've removed dependencies on aquery.

hence i'm not sure whether should follow demo activity or not

update 2:

this thing confusing me in intentservice, onhandleintent method calls stopself after finishes tasks, when want code in intentservice keep running time

protected abstract void onhandleintent (intent intent) added in api level 3 method invoked on worker thread request process. 1 intent processed @ time, processing happens on worker thread runs independently other application logic. so, if code takes long time, hold other requests same intentservice, not hold else. when requests have been handled, intentservice stops itself, should not call stopself().

signala running on thread creates , starts connection, network access done in background. remaining work on starting thread lightweight, hence ok on ui tread.

to answer question, need have thread running signala connection. therefore think service best choice since signala need running time.

regarding aquery , demo project. removed dependencies aquery in libraries, not in demo. clear, don't need aquery run signala.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -