Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I’m developing an application on Xamarin (Android) and i have a problem related to the life time of the application.
I need that the app I’m developing, run on the device for some days (for example, 3, 4 or more).

What I have tried:

To do that, I already implemented Android Service that are making the App run on device, for a long time, without stop, and executing the pretending operations. The problem is the fact of the user execute more application on the device, causing low memory issues, that android deals with it, by killing running app to start new ones.

I already tried to implement the application as a GPS (cause Android, consider with high priority), but without success! Happening the same situation, of stopping running processes.

I think about an option that was the creation of a second application which check if the first one is running and case not, start. But it’s not very practical.

I would like to know if someone have a suggestions that can be useful to solve this problem?

Or if what I’m trying to do, it’s not possible to do in one application?

Dave Kreskowiak 16-Nov-16 11:09am    
I don't know as I've never done Android development, but I would probably start by Googling for "Android Xamarin prevent application sleep".
Richard MacCutchan 16-Nov-16 11:43am    
You don't have a lot of choice, since the running apps are controlled by the user. So if the user loads up new apps and memory gets low then your app gets kicked out.

If you actually think about it, allowing any app to lock itself in memory for long periods of time could make the device unusable, which is not a good idea.
RickZeeland 16-Nov-16 16:03pm    
In Windows applications you can use Application.Restart e.g. in the Close event, but I don't know if you can do this in Xamarin.
johannesnestler 17-Nov-16 6:00am    
I'd quetion your requirement too - a forced long running app on a phone is not a good idea. Maybe you can give us some hints what you want to achieve, so maybe a better solution can be found?
Mike (Prof. Chuck) 25-Nov-16 15:42pm    
You can return START_STICKY in the onStartCommand of your service. We use that in our SIP app too.
Keep in mind, your service has no UI --- u simply can not force android to keep your activities alive.
But you can keep your service alive.
So choose your architecture in a way, that your critical tasks that need to be up are part of the sticky service.
You have to consider several things here:
- Android 6+ in doze mode shuts down network. If you need to be reachable from outside (like incoming sip calls) use push notifications.
- you can *not* communicate to the internet at 24/7 in android if the device is unplugged from power source. doze/deep sleep wins. accept it and plan your app accordingly.
- the device wakes up after 2 hours of deep sleep for a small maintenance window - you get some seconds cpu time then before it sleeps again. next maintenance window is more than 2 hours, the next even more... and so on, until the user turns the screen on. the USER - not a program part that just sets a wake lock.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900