简体   繁体   中英

Android SIP Service Persistence

I have a messaging and SIP app that needs to listen for received messages, incoming calls, etc. in the background, and then display or output them in various activities (depending on message type). My question is: what is the best way to accomplish the SIP part of this? AsyncTask, Service, IntentService, etc.?

So, when my app starts, I initially start a startup activity which shows a loading indicator, shows loading status to the user, takes care of some initial things (like checking in with our server application, setting sound level, etc.).

At that point, I'd like to then register as a SIP client with my SIP server, and sit there listening for incoming calls in the background, while other activities may run in the foreground (like a clock or WebView with a web page, etc.). If a SIP call comes in, I need the background SIP client to answer it and take over the screen from whatever activity may have been there.

Originally, I began with an AsyncTask for my SipListener class; but have two concerns: 1) I don't want to risk memory leaks, and 2) I couldn't get the SIP client to persist after successful registration with the SIP server (so, no incoming calls were being listened for, much less answered).

Next, I tried porting my SipListener class into a Service . But the problem was that I couldn't even register because SIP is a network service and I was getting Network-on-Main-Thread exceptions.

Now, I'm seeing this IntentService option, and wondering if that's the way to go?

I'm learning Android, so I know just enough to be dangerous, as they say! Can someone point me in the right direction?

You can implement Sip in service, not only listener, and start an activity or push a notification on incoming call (messages).

if you want to challenge yourself check out Linphone for android . Try to build it, it will be great practice for you, use it and customize. Also they have a Service , that can help you.

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM