0

I'm quite new to android. I'm building an application that uses the android smack library to communicate with my XMPP server. I am able to send and receive messages perfectly however what I want is to run this ENTIRE sending and receiving messages code to a long term running process in the background and on receiving a certain message I want to launch a screen (something similar to the incoming call screen of android) no matter what the user is doing on his smartphone i.e. when the activity running the messaging service is not open (in a similar way when you get an incoming call from a viber contact and you get faced with the screen even though you obviously dont have the viber application open). Any ideas on how exactly to do this ? I have a few ideas in mind after research but dont quite seem to get the correct way and glue all peaces together.

Thanks in advance

user3071611
  • 53
  • 1
  • 5

1 Answers1

0

you can use intentService to communicate with mainThread

here is a basic examples of intentservice and service

http://mobile.tutsplus.com/tutorials/android/android-fundamentals-intentservice-basics/

service example

http://www.vogella.com/articles/AndroidServices/article.html

here is an official document

http://developer.android.com/reference/android/app/IntentService.html

Hardik
  • 17,179
  • 2
  • 35
  • 40
  • ok this is great for moving processing of data away from the UI thread and doing a lot of work in background processes. I also understand how I can use the intent service to pass data back to the main thread and utilize it however what I still dont get is how I can display lets say a pop up window or some screen when a certain event is triggered and have this screen/window appear regardless of whether the main activity is open or closed (like what happens when you get a text message on viber. You get a pop up window even if ur phone is in standby mode). Any help would be appreciated and thanks – user3071611 Dec 17 '13 at 10:53
  • if you want to do as you said then you can use polling or socket connection see here this answer http://stackoverflow.com/questions/7433774/android-sockets-vs-polling – Hardik Dec 17 '13 at 11:08
  • and this might help you http://stackoverflow.com/questions/6052426/best-way-to-have-an-android-app-poll-periodically-in-the-background – Hardik Dec 17 '13 at 11:10