StaticBR
StaticBR

Reputation: 1049

Android app that survives Memory Clean

I'm trying to write an App that has to have an Background thread always running. (Yes I know that is not recommented, but this App not designed for common market and a background thread definitly the only way to do it!)

So i create an Service (as a new Process) start it in the foreground mode. And within the Service I'll start an thread that monitors the Logcat output from the System.

So everything works just fine, until someone goes to the Task Manager and hit the "Clear Memory" Button.

Unfortunately I could not find any possibility to survive this memory clean. I have tried various ways to get the Service to survive this, I even tried to set an repeating Alarm to the AlarmManager, but even that gets canceled.

I'm pretty sure i missed something, has anyone an Idea how to get an Process / Thread to survive this "Memory Clean" button? Thanks in advance.

Upvotes: 4

Views: 1266

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007276

So i create an Service (as a new Process)

Please get rid of the extra process. It is adding no value to you, and it is wasting CPU, RAM, and battery.

So everything works just fine, until someone goes to the Task Manager and hit the "Clear Memory" Button.

There is no "Task Manager" in Android, and there is no "Clear Memory" button in Android. You are perhaps thinking of something added by a specific device manufacturer.

I'm pretty sure i missed something, has anyone an Idea how to get an Process / Thread to survive this "Memory Clean" button?

If "Memory Clean" is the same as "Force Stop" in the list of running apps in Settings, you cannot "get an Process / Thread to survive". The user is welcome to terminate any application she wishes to. In fact, on Android 3.1+, "Force Stop" means that your application will never run again, unless the user later on manually launches one of your activities.

You are welcome to create your own firmware, with your own native-code daemon processes, and those cannot be "force-stopped". Anything that is installed as a standard SDK application, though, can be force-stopped.

Upvotes: 2

Related Questions