0

I have developed one application which will have activities and one background service and all activities will have to bind with service when any request has to be sent to the server and response will be sent back to the register activities.Now there is one requirement where my application can run in foreground as well as in background also so for that i overridden device's back key and called moveTaskToBack() method and observed that my application is running perfectly when it goes to background, till this point application is working as expected but when device goes to sleep mode after some time application get closed , so we observed that as Wi-Fi is getting turned off so application's socket connection is also getting closed then we have acquired the partial wake lock of the application and application is working fine when it is running mode and device goes to lock/sleep mode but when application goes to background after 15 to 20 mins it is getting closed and when i see in DDMS it's displaying "Excessive wake lock in the application" then closing all windows and killed the application process. I am acquiring partial wake lock in background service's onCreate() method and releasing it in onDestroy() method.

does anyone help me out why it is happening and how to resolve it.

Regards, Piks

piks
  • 1,621
  • 8
  • 32
  • 59

1 Answers1

1

Well, apparently OS is smarter than you. It just tries to preent your application from sucking all the battery juice. To resolve this problem, you have to be polite citzizen. (and trust me, your application will be thrown off user phone on the spot when it behaves this way.)

Why it has to run all the time at all?

Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35
  • Forget about what will happen to the application if I will acquire lock, please provide me the solution of this problem as it is the requirement from my client. – piks Dec 28 '11 at 03:35
  • Dianne locuta, causa finita: http://www.mail-archive.com/android-developers@googlegroups.com/msg138995.html - You hog the lock, we will kill you. You need to educate your client about possibilities, and look to work around this conditions. – Konstantin Pribluda Dec 28 '11 at 07:32
  • Okay, accepted.could you please suggest me any other way to achieve it? – piks Dec 28 '11 at 08:52
  • It really depends on what you like to achieve. It's really unwise for mobile client to hold open socket all the time. Periodic updates via kind of stateless protocol ( REST-Service ) are better way ( different ake-up modes are there) . Also consider whether mobile client really needs updates when it is located in a pocket and user is not interacting with it. (most probably not) – Konstantin Pribluda Dec 28 '11 at 08:59
  • Thanks, shall i tried to change Wi-Fi sleep policy to NEVER and verify whether connection is persistent or not? – piks Dec 28 '11 at 09:27
  • I zhink you should not meddle with networking connnectivity at all. Just check whatever is there, and mybe inform user to activate WiFi. You can lose connectivity due to a lot of causes. It's mobile device, you shall be prepared for losing connectivity, losing power, incoming call which forces your application to quit etc. – Konstantin Pribluda Dec 28 '11 at 09:53