When Android Service code in a Google Play app will be updated? - java

I have an Android app published on Google Play. When the app is launched for the first time (it is done by storing and checking boolean flag "FirstLaunch" in SharedPreferences), it launches a Service which will be launched once a day (=every 24 hours using AlarmManager).
For the sake of simplicity let's say that this service just shows a Toast with "Hello World!" when the time comes.
Let's assume that there is a user who downloaded and installed my app from Google Play.Let's also assume that I have changed some code in that service (e.g. changed the Toast from "Hello World" to "Hello Universe!") and updated the app on Google Play.
If that user updates my app, will the service start showing new Toast text ("Hello Universe") once a day, or will it still show the old version ("Hello World")?
Generally speaking, if I am changing the code of a running service, do I need to relaunch it programmatically in my app, or will Android itselft change/switch its code to the new version?

Android services runs as part of your application process, when the process is terminated your services will be terminated as well (it will be restarted if its start mode is sticky which will restart the whole process), so when the user updates your app a new process will be started with your new code

If Android updates an app (through the PlayStore of course),which you are currently using, it gets terminated. Services get terminated as well. So if users of your app receive their update, their service gets terminated and restarted, if thestartmodeof your service issticky or it gets restarted by your app.

Related

How to handle app kill scenario in WorkManager?(workaround)

I'm using Work-manager for some background task, as per the documentation Work will be stopped when app is killed/force-stopped until the user reopens the app next time.
Is there any way I can restart the work even after the app is killed?
I'm using onetime work request
val uploadOneTimeWorkRequest = OneTimeWorkRequest.Builder(UploadWorker::class.java)
.setConstraints(constraints)
.addTag(TAG_UPLOAD_STATUS)
.build()
Unfortunately, no. Force stop stops the application as a whole, all of your services, processes and everything permanently. When you force stop an app, it cannot even receive notifications, so, I'm pretty sure user needs to restart the app to get the job done.
By the way, getting an exception or swiping the app from recents is different, they allow work manager to process its jobs. My answer is only for explicit force stop.

Uninstalling addons when main app is uninstalled

I want to create an add-on for an app, which the user can download from the Play store separately, and it will function with the aforementioned app that i've created.
I am using service, as this is the only clean way that I've come across for this. It works well with the "Base App" which I've created but I have no way of having it get removed when the user uninstalls the "Base App". I do know that i can essentially "Throw a dialog" up if the user attempts to uninstall my app, but i feel that has a more malicious feeling to it than what I intend. I don't want to interfere with the uninstalling of my app, simply I want to have the secondary addon service be uninstalled too.
You can listen to the broadcast to see if your main app is being uninstalled. See this for more info:
Android: Listen for app installed / upgraded broadcast message
When you detect that your main app is removed, your add-on app can suggest/remind users to uninstall add-on app using Android notification.

Is it possible that the service still runs after the app got killed with task manager?

Hello im triying to run a service in background that it doesn't stop when app is destroyed by task manager. The idea of the service is verify every "x" min if there a new insert in a database that i got in a server.
The service is running great even if i close the app but when i use the task manager to destroy my app all the threads are closed too.
So i want to know if its possible to run a thread that ask in background forever unless user cancel it in the app itself, that ignore the destroy caused by task manager so in the future i can use notification bar to tell the user that a new insert happened in the database.
Tryed:
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
askServer(); // i made a timertask that ask every "x" minute
return START_STICKY;
}
As i read START_STICKY should run again the service if it get killed for some reason and i know that this can be done since some app get closed by taskmanager and still get notifications from it as whatsapp,bbms and others. Please tell me if im wrong in anything and thank you for reading!.
UPDATE: Im not trying to break any law or security rule from Android and im not trying to ignore the stoping services option from an app in settings. I want that the service that listen for new incoming "events " inserts in my case keep running after user used the interface that appear when you press home for a while :
UPDATE : sorry for talking to much about this app but is the one that i can use as an example. In whatsapp when i close the app by the interface that i showed above the process and services are killed but after a couple of second they relaunch, this is exactly what i want to do to keep user informed about database events. From setting you still can stop the service without problem or even i can put the option in the app itself to stop notifiying.
Is a bad implementation call in OnDestroy() method an instance of the service so it relaunch after destroy?
UPDATE : welp looks like my service is still running on background after i close the app. I will just have to work on my service design to not waste battery life and resources. Also i was using the log.i() to check if service was running, looks like when main process closes i can't use log or toast just notifications ( still not implemented) because the service is there running just won't show in log .
UPDATE : now is working using using startForeground(0, null). In future i will send a notification to show when a event on database happen building it and calling startForeground(1, notification).
For services, look at Settings -> Applications -> Services. and see if it is running.
However, poorly designed services may run more often or perform syncing operations. So yes it is possible.
I had a problem similar to this when developing my first android game; force-stop was the only way to kill it.
START_NOT_STICKY will kill the background service when you swipe the app away from the task manager. START_STICKY is, as the name implies, "sticky", Meaning it sticks to the android system even when the app is gone.
That's from my experience, anyway.

Files saved in device internal memory getting cleared when the application is closed from multitask window in Android OS 4.2.2

Our app saves application data to internal memory using the Context.getDir(foldername,Context.MODE_READABLE | Context.MODE_WRITABLE). The app data works fine on all platform except Android Samsung Galaxy Nexus 4.2.2 and Google Nexus 4.2.2, when the application is closed from the multi task window, by swiping the application out from current running application list. If the appllication is exited normally, by pressing back, back.. button the app data does not get affected.
We tried the same steps on HTC One 4.0.3, but the issue is not reproducible and the app data does not get cleared when the application is removed from currently running list from the multi task app running view. I have debugged a lot, I couldn't find any issue with the code. All the file streams are closed properly. Also when we set the following setting under developer option, Background process limit to No Background processes, the app data is not getting cleared on Samsung Galaxy Nexus 4.2.2 and Google Nexus 4.2.2.
If we set the Background process Limit back to Standard Limit and Close our application from Multi task application View on the device homescreen, the App data gets cleared, hence all the information of the user gets cleared.
Our application has multiple activities, When the Application is send to background by pressing Home Button from the Launcher Activity, and then closing the Application from Multi Tasking Window View, the App data does not cleared and the issue is not reproducible on Samsung Galaxy Nexus 4.2.2 and Google Nexus 4.2.2.
But when the Application moves away from Launcher Activity to other Activity of our Application and then our Application is sent to background, by pressing Home Button and then closing our application from Multi Tasking Window from the Device Homescreen, the Files saved using Context.getDir(foldername,Context.MODE_READABLE | Context.MODE_WRITABLE) is getting cleared.
I also tried to reproduce this issue on Android Emulator 4.2.2, but it is not reproducible and it is working perfectly.
I am not sure why the internal memory files are getting cleared by the OS and how is it related to the Limit Background Process, as our application is working perfectly with No Background processes, but it is getting cleared in case of Standard Limit which is the Factory Settings in all Devices.

Android 2.3X kills Apps into the Background

I always used Android 2.2 for my Apps. But currently I upgraded to Android 2.3.X Gingerbread. So if I start my App and go back to the android "desktop", the app is kill by 3-4 Minutes.
I think it will be killed after some minutes inactivity, but I need to run it in background to read some mobile status.
How can I set my App as a "Background" App, so that Android will not longer kill it?
Thanks for Help...
Regards, Rookee
To run an application in the background it must be of type "Service". You have to register a service and it will run in your device forever. For more info, Android Services

Categories