I've been trying out the new Android WorkManager API and it seems to work fine. However I noticed something while testing my app: before creating a new periodic worker instance, I check for status to avoid creating more than one:
WorkManager.getInstance().getStatusesByTag(myTag)
.observe(lifecycleOwner, Observer { status ->
// creates a new worker if status returns nothing
})
The first time app launched the status returned nothing and a new one was created, but then I needed to uninstall my app and when it launched again there was already a worker created, from the logs:
WorkStatus{mId='UUID', mState=ENQUEUED, mOutputData=androidx.work.Data#0, mTags=[tag, tagName]}]
I know the API is still in alpha, but I was wondering if this is expected and if this won't be a problem. I think that if user uninstalls your app these background tasks should be removed too. I've been trying to find some information related to this, but I couldn't so far.
Has anyone seen this or can anyone point me a documentation or something similar?
Thank you for your help
Of course NOT. Once you uninstall the app there will be no instance of WorkManager.
WorkManager API will work even if your app is process has been killed but not after uninstallation of app. WorkManager API implementation is part of your Application but not Android OS.
Please check your uninstallation again.
Related
My Android Flutter app uses the AppLifecycleState to determine if the user is returning to the app. I have a stream set up from Firestore for new data from any document. But if the app is in the background, the stream eventually is paused. To fix this I make a call after AppLifecycleState.resumed is triggered and make a separate call to fetch new data. The stream seems to resume after. Although, if the app sits in the background for an extended amount of time my app seems unresponsive. Agains this would be a couple of hours or so. Any idea on how to fix this?
When an app is no longer visible on screen, the host operating system will eventually pause, then kill the app's process, in order to free up resources for other things that need to happen on the device. The fact that your app seems unresponsive is because of this behavior, which your app should fully expect. Your app can not run forever.
If you want some ideas to work around this, start reading here: Flutter: cross-platform way to keep application running in the background
From the 2018 Google IO session Migrate your existing app to target Android Oreo and above, they mention that there is an exception for not being able to start services in the background when it comes to a response from notification actions. What exactly does this exception mean?
We are currently using a WakefulBroadcastReceiver to receive the action, which then generally starts a Service to run a network request and take action on result. I want to make sure that we are making the proper changes necessary (likely, using a foreground Service, if it is necessary. That being said, I don't want to make changes if they are not needed.
Does anyone know what the exception to not being able to start services while in the background actually means here and if there are any exceptions that may break this model (being in battery saver mode, for instance)?
In my testing on a Pixel 2 running Android P I have had no issues with this, but I want to make sure my users will not either.
i'm creating android app, and using Firebase.
I have 'Missions', and 'Mission' have status.
If the status changes to 'Active' - I need to 'Wake up' my app and run the code of 'ActiveMissionActivity'.
(The work of the service should be just 'Waking up the app' and go to another activity)
I could write missionsDbRed onChildChanged listener which will be activated when the status is active - but only when the app is running.
What is the good practice for this issue? My friend suggested me to use 'Android Service', but i'm not sure which type do I need, and if there is something that works well with the Firebase DB.
For example i've seen 'Firebase Cloud Functions' But i'm not sure which one is more suitable and why. Thanks
As push-notifications are not a solution to your issue, the best way of handling this matter is by building a service that checks (in the database) if the value you are interested in has changed.
Now regarding the service, a bad idea would be to run a service that continuously checks that value. This would result in a huge battery drain and you risk your process to be killed as android is freeing up resources. you can notice this here.
You can fix this by telling the service when to start checking the value you are interested in.(e.g. by using Alarm API and assuming you know when this should happen) You can see something similar here.
Keeping your service alive as less as possible is probably the safest way.
As for google cloud functions, you might wanna use those for sending notifications prior to the actions that happen through the service you established.
So if the status changes to active while your app is closed, so that means the value changed somewhere out of your app right? If that's the case simply send a push notification to users device to wake it up. It is a lot more performant than using a background service.
The latest release of Xamarin.Mobile component obsoletes some Task-based APIs for Android. Release notes briefly comment on this:
Given the fragility of the Task<> based API on Android due to Activity lifecycle realities, the async API is now marked [Obsolete] specifically for Android.
Could someone please explain what fragility is meant here?
Essentially, using Task across app lifecycle boundaries is asking for trouble. When the camera Activity starts on Android, you are actually starting a completely new app. Your app is no longer running in the foreground, so Android is completely within its rights to kill off your app and just restart it when the camera returns. If this happens, your Task instance has been destroyed and so any awaits or ContinueWiths you have will never execute. It's not a Task/Android issue, it was simply a design flaw in Xamarin.Mobile.
As a result, the magic API was deprecated in favor of one that utilizes OnActivityResult, as it is the only way to properly handle this situation. If you notice, the new API GetMediaFileExtraAsync still returns a Task<MediaFile>.
(Source: I wrote Xamarin.Mobile).
I have a very common problem but wasn't able to find a proper solution/pattern to solve it. My application has two kinds of data that need to be automatically updated:
general data
user-related data
If the user is not logged in, only general data are downloaded and displayed, if the user is logged in, his/her data are handled too.
I need to periodically download these data from a Web service, starting from the boot of the device (after the action android.intent.action.BOOT_COMPLETED is triggered).
Since my app can be moved to the SD, I will also need to register for the android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE action.
Issue 1: starting from API level 11 (Honeycomb) all actions aren't sent to applications in a stopped state. I haven't quite understood this, does this mean that my app can't listen for actions if it has just been installed and never opened (so only once if we count updates out)? Or does this mean that, after every system reboot, the action will be triggered only when the application starts?
Issue 2: if the application has been moved to SD, SyncAdapters won't be able to be run, so I have to rely on the general BroadcastReceiver-Service-Alarm-PendingIntent strategy. But how can I understand if the SyncAdapter won't be started by the system? (I already handle Accounts by the AccountManager)
Do you know of any library that takes care of all of this? It seems quite strange, isn't this a common issue?
Re: issue 1, as far as I can tell, an app is not "alive" until the user explicitly runs it for the first time. It will then still be "alive" until the end of the days, unless the user explicitly stops it using the Force stop button in Android's Applications management settings. He will then have to re-run manually the app for it to be able to receive broadcasts and stuff.