-1

I have a voice recognition application, when the user press the home button it goes to background and still listening for commands. It works fine on 2.3 and up except in Jelly Bean that kills the activity in a few seconds(on ICS can also happen, but usually keeps running). Is there any way to avoid Jelly Bean to kill my activity?

Thanks,

Carlos.

  • Check out the Activity Lifecycle section [here](http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle). I don't think you can keep Android from killing your activity if it needs the resources... Someone please tell me if I am wrong. – TronicZomB Mar 05 '13 at 19:18
  • @TronicZomB I believe you can by registering as a service (Which, I admit, is not a good answer as it's a fairly fundamental change to your app) – Basic Mar 05 '13 at 19:25

2 Answers2

2

Is there any way to avoid Jelly Bean to kill my activity?

Android will terminate your process sometime after it goes into the background. This is completely normal and expected. The precise timeframe will vary based upon device, OS version, and what else is going on.

You are welcome to attempt to rewrite your application to move the voice recognition into a service, perhaps even a foreground service (via startForeground()). Using a service will increase the lifetime of your process somewhat. Using a foreground service will increase the lifetime of your process significantly.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    It's worth noting that if you're going to be running all the time, you need to make sure the code that executes doesn't do too much or you'll start to impact battery life. Nothing gets an app uninstalled faster than killing the battery. – Basic Mar 05 '13 at 19:27
0

You shouldn't rely on your activities when writing application logic. So you will need manage too much events according to android activity life cycle. There is Service that you should use in such situations

Lazy Beard
  • 305
  • 3
  • 10