Flutter app stay running while in background - android

I have an app I have building that is giving navigation from a location to a location. Contstantly tracking where the user is using GPS data in order to give good Directional information. Currently if a user switches from our app to another app or goes to the Android home screen, after one minute Android turns off our app for performance reasons.
I have tried using an Isolate but like flutter this gets shutdown. Next step were to use a kotlin service to handle background things but i wanted to check if anyone had done this in dart yet?
Also this is not an app that will be in the play store or on public devices. It is going on special devices that we control and are less worried about memory usage as this will be the main app ran on them.

as mentioned above in the comment by #galloper background_fetch is the thing you need, it has a method called BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask); where backgroundFetchHeadlessTask is a function that will keep running even when the app is close, i used this in my app to stream location info to server.

Related

Keep Flutter application active on device at all times, possible?

A client of mine is requesting for a very specific functionality, to keep the application always active, even after the user force kills it. He wants to ensure that the users have the application active at any time while using the device on which it is installed (the devices are managed in a constrained environment).
I've done some research on it, and already enabled background services for sending the user's location, but if they force kill the app then we are unable to send locations to the server. We've seen other apps do it, but wonder how they do it.
According to https://stackoverflow.com/a/34573169/640907 it should be possible in Android. We also found https://ssaurel.medium.com/how-to-auto-restart-an-android-application-after-a-crash-or-a-force-close-error-1a361677c0ce but I don't think this will work for our use-case, as the user can close the application without "force kill" aswell..
Anyone knows how to achieve this for a Flutter application?

Android app automatically casting without user interaction (CastCompanionLibrary)

I have an Android app using the CastCompanionLibrary v2.9.1, modified to use play-services-cast:10.0.1 (just a simple change to the gradle dependencies).
Short version: The app is attempting to automatically connect to the ChromeCast device, without user interaction.
Long version:
Since updating the CCL library to use play services 10.0.1, I've had several users mention that the app is automatically connecting/casting to ChromeCast without user interaction.
Some users have said they're not using the app, then they connect to WiFi, and the app automatically attempts to cast. Others have said they are using the app, they don't press the ChromeCast button, and the app begins casting.
--
I'm having trouble figuring out where to look for potential changes to the ChromeCast APIs which might explain what's going on. I'm also not sure whether this issue is only occurring for my app, or for many other ChromeCast enabled apps. Lastly, I'm not able to reproduce this issue on my own ChromeCast device.
Any help would be appreciated.
I had not seen or heard this before, so here are some pointers for you to do further investigation to see what can be the cause. CCL has a (sticky) service called ReconnectionService that is responsible to perform reconnection attempts when you lose wifi and later gain it back. The wifi scenario you had mentioned resembles this so I would suggest to start from there. In order to only reconnect when it makes sense, it gets the time length of the content that is playing and only makes such attempts for that period of time; i.e. if you start playing a content that is for 1 hr and then you leave your phone on the table and pick it up after 2 hrs, it notices that the last movie before it fell sleep was for 1 hr so it won't make any attempt to reconnect (see handleTermination() in that same class). For live-stream that doesn't have a clear content duration, CCL uses a default of 2hrs but allows apps to modify that by calling VideoCastManager.setLiveStreamDuration(duration_in_seconds) method. Finally, the whole reconnection relies on a few factors: it saves the route-id of the last connection, along with the session ID. So if needed, you can clear any of these and then it won't try to reconnect for that particular session (in case you want to keep reconnection for some and disable on some other). Hope these help to troubleshoot the issue.
So it turns out there's a bug in Android Support Library 25.1.0 which was causing this issue.
https://code.google.com/p/google-cast-sdk/issues/detail?id=1105
Which is now marked as 'fixed internally'.
Also related:
https://code.google.com/p/android/issues/detail?id=232326

Webapps in Android: Get new content without website reload

I have an android app which is a wrapper around my mobile site. We have a site that changes everyday, and I’d like to have a method by which I can notify the user that there’s new content to be had, or just reload it programmatically.
This obviously happens when the app relaunches, but sometimes users will keep the app in sleep mode and re-open it the next day and they see a stale version of the website. Is there any way around without going native? One method I thought off was using a push notification to reload the app (i.e. use GCM to tell the app to reload the page) except I don’t want to push a new version as this would require permission changes and that would break auto-updating. I though of using socket.io for the task as I'm already using it in my app but I don’t think it'll work if the app is the background (will it? I’m an android newbie)
Thanks for any help!
When the application returns from sleep - onResume() of the activity life cycle may be invoked. If you reload the webview on this listener, that should resolve it.
Unless i am missing something very significant, this simple solution might work.

Keep android application open

On the Android Market there is an app called Sleep Timer, and it is a type of alarm clock that brings runs the alarm even though you locked your phone while on facebook. I made a type of app that detects movement however it only works if the phone is left on that app... How can I make it work when the app wasn't left upfront, but is still running in the background?
You should take a look at Android Services, which provide the functionality you seek. Basically they enable you to create components that run in the background even when the user switch away from your application.
You can find a very good introduction to them here: http://developer.android.com/guide/components/services.html

programmatically temporarily disable auto-update

I have a Bike computer app that logs data while the user is riding. I have had a user report an issue I had not considered. He was out for a long ride (100+ miles) but while out and logging data the app got updated via Google plays auto-update. This unfortunately killed off the app mid recording and the user lost data till they spotted what had happened and restarted the app.
Ideally I would like to be able to programmatic stop the auto-update happening while the app is data logging. All my research indicates that this is not possible possible but I may of missed something so dose anyone know of a way of doing this?
Given no solution the best I can do is advice the users to enable the update only over wifi option in the Play app which in this instance would of helped. Unfortunately one of the key points about my app is that it will log indoor sessions using ANT+ sensors so I have a good number of people using it with wifi active.
Edit
I managed to do the experiment to see what happens myself last night. I had an app going in the background data logging then pushed a new version to Google Play. Unfortunatly it was not picked up totaly automaticaly when I had to leave 10 hours latter but I opened up the play store app and it found the update it did not start updating automaticaly but I forced it. The act of downloading and installing the new version killed off what was in progress. It was already dead before I used the notification to go to the new version.
As you say yourself, you can't do that what you are asking for. You could hack your way around it by changing the permissions each time you update. The users will then be prompted about it in the regular way.
I'm not sure about the "life-cycle" for automatic updated apps that are running. But I read somewhere that is wasn't the re-install but the reopen of the app that crashed it. If that is the case you could set a flag indicating that the user is currently logging and then on restart just resume the logging. But again we need to know more about the inner workings of activities/apps which are running and get an automatic update (actually didn't think it could happen).
Edit
Based on your findings I'd say you have to handle the app is shut down in onDestroy etc. or/and make sure you save everything persistently. Then you might need to have 2 apps where 1 listens to the other being re installed and when that happens it starts it up again (there is an interesting discussion here). If you are targeting api >= 12 then the broadcast action ACTION_MY_PACKAGE_REPLACED might also have interest.

Categories

Resources