I am trying to understand how I can create a background process in a Flutter Application. Basically, My understanding is that once a user has started the application, the Isolate can be created. This will allow my code to run on the background.
In the background, I want to get a list of Bluetooth enabled devices and their RSSI values within a certain radius, every 30 seconds or so.
I am aware that there are some Bluetooth libraries available for Flutter, but Time is really limited and It would be best to seek advice from experienced flutter developers.
Specifically, I would like to know the following -
Is using Isolates the best way to go about doing this? From my research, I understand that the user has to start the Isolate through some UI Activity?
Could the Isolate(Background Service) repeat every periodically to perform certain tasks?
I need to be able to write the data received from the Bluetooth scan to a database. I understand that the Isolate will not be the best place for this? Based on this blog post by Ben Konyi, it is not good practice to do such tasks within an Isolate.
Related
I am developing an app that should fetch an API periodically (every 15 or 30 minutes). I am using Flutter for the frontend development. The app should be available for both Android and iOS devices.
The background task includes a call to the backend. In the backend, a worker is determining certain data (this can take up to one minute) and sending it then back to the frontend. The task has to be (at least partially) initiated by the frontend, as an decryption key is passed to the backend.
I had the idea to use Firebase Cloud Messaging to push the requested data to the devices. Unfortunately, it seems to be necessary to have the Apple Development Program enrolled to use it. As the app is an university project, and I'm not even sure, if the FCM approach is the best one, I don't want to pay the 99€ for the enrollment.
Beside the FCM approach, I found some flutter packages like "background_fetch", to pull the data instead of pushing it, which wouldn't be a problem for me. But all packages I found have the problem, that they work differently on iOS and Android, and are also not very reliable in terms of background task management by the respective operating systems.
Is there any "simple" solution for this problem, like a flutter package allowing me to schedule periodic background tasks on both iOS and Android, which is mostly reliable in that the time periode is respected at least roughly and the background task is not killed while waiting for the response? Or will I have to implement an own server-side Push-Service to avoid the costs for the Apple Developer Program?
Thank you in advance!
This question is about the flutter framework.
I am looking for information about how to schedule background tasks in the app while the app is being used by the user. It is not necessary to run the task also when the whole app is in the background / closed.
To explain, an example:
User starts the app and goes to a news article. The page is finished rendering and the user starts reading. While the user is reading I want the app to do tasks in the background such as checking whether there is new data that can be written to the database or maybe that avatar's from other user have update and it should be updated on the user's phone.
Does anybody know where to look for this?
If it's a simple task, you may use Timer:
https://api.flutter.dev/flutter/dart-async/Timer-class.html
But it can't broadcast messages, so you should either use a provider or if it's time-critical and it's a heavy task you should use isolates:
https://api.flutter.dev/flutter/dart-isolate/Isolate-class.html
If you are unfamiliar with isolates you can use ready-made packages, like this one : https://pub.dev/packages/flutter_isolate
I am about to start work on a project that will aid in teaching new vocabulary, in an interruption-driven style, presenting new words, via interrupts, for the user to learn at optimal times.
I am looking for a way to detect which app is running. I found some posts that touched on retrieving the running app list part of my question, "Can we retrieve the applications currently running in iPhone and iPad". Is this still viable to use in iOS 6?
I cannot find any relevant posts about retrieving data about the type/category of app that is running (media player/game/pdf viewer etc.). Do iOS apps contain any meta data or way of retrieving this type of data?
Naturally, to interrupt the user at an optimal time it would have to take the type of app in use, into consideration.
I am open minded about alternative ways of detecting when interrupts may be optimal and open to criticism of my current plan.
You can get a list of running processes (aka apps), as noted here, but you can't get any meta data on them from the OS. From a UX perspective, you might consider a solution where the user manually schedules the interruptions, or gives you a schedule window. For instance, maybe every day between 3 and 4, start notifying me. Personally, I delete spammy apps super quickly, so I'd consider doing something other than interruptions.
Is there any easy and effective way to track user activities from my iPhone app. I have to record all actions performed by user in my application without any performance/frozen problems. There should be no limits like per second hits etc.... App is global and cross platform. It is better if I can write my own custom algorithm to make this functional.
You can also use google analytics
https://developers.google.com/analytics/devguides/collection/ios/
We use a service called Flurry Analytics. It works on all mobile platforms and we have had great experiences with it. Free too!
http://www.flurry.com/flurry-analytics.html
The app can collect all kinds of information in a very versatile manner and is efficient in when it sends the data back the the server. I believe it's only when the app terminates.
On the device side it is super easy to set up and beginning tracking user events.
I have Android application where service running 24/7 Phone get's GPS position every 5 minutes and sends to server. This is requirement.
Can I write same service for iPhone? I'm not sure if it's possible.
Can I write same service for WP7? I think it wasn't possible to run service before. Did anything change in 7.5?
EDIT:
I'm not sure why somebody downvoted. This is concrete Yes/No question.
It is possible in WP7 with the introduction of background tasks in Mango. In fact, there is a built in mechanism for polling the GPS provided by the API that is more battery efficient.
Not sure if it goes down to 5 minutes, think it is something larger like 30 minutes. It is also not comparable to a Windows Service - so don't go fowards with that mind set. Background tasks are heavily constrained to keep the phone responsive for the user - to make use of them, you need to play nice with the requirements.
Background tasks introduction, it also talks about the GPS thing I mentioned. The entire series is well worth your bandwidth and time downloading and watching:
http://channel9.msdn.com/Series/Mango-Jump-Start/Mango-Jump-Start-06-Windows-Phone-Multi-tasking--Background-Tasks
Can't answer for iPhone.
It is also possible on ios4+ but it wont be time-triggered. Either you register for precise (gps) or vague location (wifi and wan location) which is available to get in background but it is not always possible to send that data to a server because after 10 minutes in background your app is not allowed to keep a network-connection alive. So you have to buffer that data and have to wait until the user launches your app.
The ios pushes notifications to your app depending on the needed accuracy and depending on a distance-filter
ios-apps do not differ between services and activities (like in android). it is all combined in one app.
There are "some limitations"(a lot) here too, but maybe Microsoft Push services works for you:
Push Notifications Overview for Windows Phone
Because polling is not a good practice for this, push works better in this cases.
In WP7 Mango you can't get a fresh location from a background agent. The following code will return the latest available location (up to 15 minutes old):
private GeoPosition<GeoCoordinate> GetCachedLocation()
{
GeoCoordinateWatcher geoWatcher;
geoWatcher = new GeoCoordinateWatcher(); //Start a new watcher with default level of accuracy
geoWatcher.Start();
//Get latest cached position
GeoPosition<GeoCoordinate> position = geoWatcher.Position;
geoWatcher.Stop();
return position;
}
As you can see, this uses GeoCoordinateWatcher. According to MSDN (http://msdn.microsoft.com/en-us/library/hh202962(v=vs.92).aspx):
This API, used for obtaining the geographic coordinates of the device,
is supported for use in background agents, but it uses a cached
location value instead of real-time data. The cached location value is
updated by the device every 15 minutes.
Other than that, I haven't been able to find much information. You could create a GeoCoordinateWatcher with a self-defined accuracy, but I haven't tested this. Perhaps it would return the latest available cached location that satisfies the accuracy requirement.