How to Prevent other apps from stopping background service of my app? - android

I am trying to make an app which has got background service feature.But i need it to run continously till app is uninstalled.How can i achieve it using service.Can anyone help me out.Thanks in advance.

You can't do these kind of assumptions on Android. Your app and related service might be killed for whatever. You can't guarantee that.

Read the section on "Creating a started Service" here in Services
Once a service is created, it will continue to run until it stops itself, or is stopped by the system. Why do you need it to run forever?

Related

Continue uploading even when the app gets killed(Android)

I want an upload operation to get completed even when the application is running in background. The process should get completed even if the application gets killed while opening other application. Could anyone pls suggest me some solutions?
Use a service, and attach an ongoing notification to it. This will prevent Android from killing your app by and large, but it is still possible you may be killed in the most extreme scenarios. However, this is the best you can do, unless your app is in the foreground throughout the upload.
Your application do not get killed by opening other applications. Check the Android life cycle. And the best way to upload a file is to do it on a thread. Whether you close the app or not started thread will keep working on.

No idea on how to update widget from service

I've been trying to make a widget to my music app.
The app has a service that handles the mediaplayer so that i can "minimize" the app and yet continue listening to music.
I know that i need to update the widget from the service, but all the examples i've found, wants me to start a new service on each update, and that's not what i want.
Any help is appreciated!
Thanks in advance
You can do it without the service too. The service is recommended because if your updation takes too much time, android may close it and give Application Not Responding (ANR) error message. These are the cases like when you send a web-service request. Otherwise, you can use your custom AppWidgetProvider to update your widget (without making a service), using RemoteViews(the same way you do in the service). For more on how to do that refer this

Will android services stop when I receive a phone call?

I have a doubt in Android services. I wrote a simple application with a service that runs continuously and upload data to server. My doubt is that will the service stop when I receive a phone call? Will it run in background when I make phone call or will it stop. Please give me an answer.
Thank you.
Activities stop, however services do not.
http://developer.android.com/guide/components/services.html
Services run on the background no matter what happen on the screen. It only stops if you stop it using stop or exit function of its main application or you stop the services in Settings.
Cheers,
The short answer is no. Unless the available phone memory was already low to begin with because you have a lot of apps running in the background, only then might Android forcibly close the service to accommodate the phone call.

Android immortal service

I have an application which contain an activity and a service. The activity runs the service. When I start something big like a game (for example AngryBirds), I get a message "Low memory: no more services" in the LogCat and my service shutdown. But if I run music on background it works well and continue working...
So I have 2 questions:
I guess the android killing my process, because it is contain my
activity. Am I right?
How can I implement immortal service like the player service?
Thanks
You should only do this when the user knows that the service is running all the time and has profit of this. If so, check the startForeground method on the following link:
http://developer.android.com/reference/android/app/Service.html
If not, you should improve your architecture. Most service don't need to run all the time and it might be useful to persist the data of your service.

How do I make an application run in the background indefinitely?

I am trying to make a simple timer application. I want the timer to run even after the user has navigated away from it, but when I run the application and try to come back to it restarts and the timer is no longer running if I do not come back to it in two minutes. Is there anyway to ensure that it will keep running forever without having to come back to the application every two minutes. If need by I can provide sample code or more explanation. Thank you.
Service to work the same way as this.. please check out the underlying post from me. Activities and services using handlers
make sure that the service has the timer and calls a function like this. installed in the service so that the system can be have a look at the service and other examples this gives you a pretty goood example of the how the service works how the service binds,,,, and the functionality of the timer and implementation of it and so on.
Think of creating the Service to solve your problem

Categories

Resources