What happens to background service when the app is updated in android? - android

Let's say I started a repeating background service that was stated on first app launch and on boot. What happens when I provide an update of the app. Will that background service be killed?
Will user have to open the app again to register the background service again or app will get some callback on update?
Edit-1: As one of the answer suggest if app has to be relaunched again to start the service then how does alarm application works fine after the update without relaunching(I believe it usages background service to start the alarm)?

Will that background service be killed?
It will be killed.
Will user have to open the app again to register the background service again or app will get some callback on update?
It depends. Basically it'd require user activity as app is not relaunched automatically after update. But if you target API 12 or higher (which you should nowadays) you can try to use ACTION_MY_PACKAGE_REPLACED broadcast. As per doc:
Broadcast Action: A new version of your application has been installed over an existing one. This is only sent to the application
that was replaced. It does not contain any additional data; to receive
it, just use an intent filter for this action.
so you can do you stuff either in BroadcastReceiver trigger something once you receive this broadcast.

The service will be killed and needs to started again.
A Service doesnt run on a separate process. The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of.
So when the application is updated, the application is sent to the stopped state.
You can test this.
From google play store initiate a update for the app (which has a service E.g Whatsapp).
Open the app and wait for it to complete. It stops. you can check the internal running processes. Connect the phone to DDMS. Check the processes.

Related

Android implementation service and launch in background also if the application is died

I am trying to find how to enable the application to perform a background task.
I use the example seen here "http://saigeethamn.blogspot.fr/2009/09/android-developer-tutorial-part-9.html" and I do not know if that is how I have proceed to execute a script permanently?
Also how to get it reactivated when starting the mobile?
So how should we do and if we can so that the service works even if you force stopping the application?
A big thank you for your help
No service can work if the user force stops an application. Force stopping puts the entire app into a state where no services, receivers, or activities can be run unless the user explicitly does so.
If you want to start a service when the phone starts, you need a broadcast receiver for the BOOT_COMPLETE broadcast.

Is it possible starting Android Service and Broadcast when app did not run before

If my app runs once, service can start and request to server on background. But when app did not run before, service could not start. Is it possible starting service even that app have not runned before.
Actually what I want to do is that phone can send request to server for once without even runned before. When request sended, it will be activation. Later request is not to require.
No, it isn't possible.
When your app is getting installed for the first time OR was force-closed by the user, it is in "inactive" state (meaning no broadcast receivers or alarms will work), and will become active only when the user launches it manually.
See details here

Why gmail/yahoo / what's app service is not getting killed?

I have an intent service which is continously polling to check if data has been modified in the server. The problem is if the app remains idle for some time , it stops receiving notification. We are suspecting the service has been killed by android.
I think even GCMINTENTSERVICE is also killed by android in some time.
My question is how come gmail / what's app/yahoo mail always sync without foreground notification. Which sync mechanism they are using.
Are you aware of any other app which is always receiving notification even when in background, so that I can check in Google why it is not killed in some time.
Does Google kill gcmintentservice if it has been running for some time in the backgroud.
EDIT: GCMBASEINTENTSERVICE is the service we are planning to implement for push notifications, because with the older polling service the app did not receive notification after some time. This is may be because it was getting killed by android in some time. So with push notifications, the app will always receive notification? Isn't Gcmbaseintentservice an intent service and that will also be killed by android in some time.
Android will kill services after some time, to resolve memory issues. It's not a good thing to always run your application in background, since it will consume memory and processing power.
You have got the wrong idea. GMail and Yahoo are not polling for new mail, they are using Push Notification mechanism, more precisely Google Cloud Messaging or GCM. Push Notifications can be received in the background, and once they receive a push notification, they sync the app.
BBM (BlackBerry messenger) didn't use GCM, as they relied on BlackBerry servers. So they ran the application in the background without getting killed. This is done by always showing non swipeable notification. Someway with notification, you could run a service in background without getting it killed.
According to AndroidHeadlines
You may want to leave it persistent if you want to use BBM. In Android
4.3, Google has begun fighting apps that suck down battery and stay alive without you knowing. It now requires any app that wants to run
in the background to place a persistent icon in your notification.
Hence the BBM icon. Doing this allows that particular app to never be
closed.
Surely google will kill any service if the device runs out of memory or new services are running in background.

How do Android applications such as Facebook Messenger and Llama stay running in the background from boot time?

I'm developing an application that uses a Bound Service to query information from a server and provide notifications when conditions are met. At the moment, the user must execute the application from their home screen in order to begin receiving updates. But, for example, applications like the Facebook Messenger and Llama run from the moment the phone starts in the background. How do I achieve similar functionality for my long-term application? Also, even when my application is run from the home screen, it will still ocationally quit in the background from what I assume to be the system quitting the application for additional resources. Even though my application is made to restore the service when it begins again, it never seems to restart after it quits (usually after 3 to 4 hours of background activity).
Thanks for your help.
You can register a BroadcastReceiver for the ACTION_BOOT_COMPLETED Intent to detect when the device is booted. This requires the RECEIVE_BOOT_COMPLETED permission.
Instead of using a bound Service you can use a started sticky Service. However, depending on what exactly you want to do, you might want to check if AlarmManager suits your requirements better (maybe in combination with an IntentService, cf. cwac-wakeful).

Android and background processes

I wrote an bluetooth app with my bt-connection established in a service, so the connection is still alive when I minimize my app.
But when watching my task manager, my app is still there.
And when calling onDestroy in my app, I have to stop my Service.
But other apps like telegram or skype (whatsapp too I think) aren't in my task-manager visible but by having an incoming message they notify me nevertheless.
How is this even possible? How can I write my bluetooth connection like this, that I can really close my app and anyway the incoming messages will be handled?
The other apps might be having some light weight service running in other process which gets the data for the main app.Go to settings->application manager->running processes..you will see all the service..
Other mechanism which apps use is port-directed sms. In such a scenario you don't need any service running.However port directed sms doesnt work on all the phone and for all the apps.
When you put remove your application from the foreground, Android keeps the activity on the stack again in case you will go back to it (unless you explicitly destroy the activity). So this maybe one reason why you still see it in the Task Manager.
You cannot kill entirely the app and it will still post messages. Your service will be running in the background and it will be visible in the app Manager->Running Services.
However if you destroy your activities the app it will not be visible in the app list of the Task Manager.

Categories

Resources