0

I've been working on an app, and it's came long great. I have a problem though, Android, being greedy with its resources, loves to kill the app when I put it in the background. This is very bad, because the app is actually intended to be an AI assistant, and having to reinitialize every-time I need to use it means that it's not going to be very helpful in a real work environment.

I investigated ways to prevent reinitialization of the AI's brain, however, none of the methods have been very fruitful. Saving the instance of its brain will not work, because the POS models that she needs to operate can't be serialized. And employing a service won't work either, because if I want to communicate with the activity via the service, I have to reinitialize it along with the activity (correct me if there is a way around this, I just notice most tutorials put service.start() in the onCreate methods)

Is there a way around this? I only need to preserve the POS models. They take a while to load in for some reason despite only being a few megabytes.

Please note that this is to prevent data from being killed. There are no background processes that need to be ran.

Anonymous
  • 696
  • 8
  • 21

1 Answers1

0

You need to set a Notification to tell Android not to release your resources.

See this question: How can we prevent a Service from being killed by OS? . While the question itself is not directly applicable the answers have a lot of overlap with this issue.

You should probably be using a Service if you want to run things in the background though as Activities are only supposed to run when you have a layout in the foreground. You could store your required object in the service, grab it as necessary when (re)starting an Activity that requires it and update it when your Activity loses focus.

Edit: I accidentally pasted the wrong link. Now corrected.

Also, have a look at this Android resource if you have not already: http://developer.android.com/training/basics/activity-lifecycle/recreating.html

Community
  • 1
  • 1
indivisible
  • 4,892
  • 4
  • 31
  • 50