1

I am developing an android application where socket communication is using between client and server. Its working fine in normal case. I want to keep alive socket connection with server for receive data in background also even if application get closed.

I created service where socket connection has been initialized.My service has been restart if my application has been closed because I have used "START_STICKY" that is fine. But After restarting service my service could not able to communicate with activity when I received some request from server.

How Can achieve this feature in my application if my application is closed it should be able to receive data from server and act as per that.

Please help me to design this communication.

Evan Carslake
  • 2,267
  • 15
  • 38
  • 56
ojas
  • 2,150
  • 5
  • 22
  • 37
  • You need to create a BroadcastReciever in your activity (onResume) then trigger it from your Service with some custom operations (your business), Try to check this answer maybe help you: http://stackoverflow.com/a/4739898/1312796 – Ibrahim AbdelGawad Jun 30 '15 at 15:36
  • @Heema But Activity is closed how it will receive broadcast receiver. ? – sam_k Jun 30 '15 at 15:47
  • What did you mean with activity is closed ? try to determine your activity lifecycle..Anyhow, If you registered a receiver in your activity (OnResume) it will be trigger by the BroadcastReciever. – Ibrahim AbdelGawad Jun 30 '15 at 16:00

0 Answers0