Comments (11)
My assumption about logging in background was wrong and both of you were right. Although The callback(LocationDto locationDto)
is getting called even if app getting terminated (removed from recent), BUT the ReceivePort
stop listening as soon as app get terminated.
from background_locator.
I have the same question, I came accross this medium article where when flutter is killed the sticky service listen to this and start FlutterNativeView
wich is different than FlutterActivity
to execute a dart function, so there is no UI drawing whatsoever in the background. You need to wait WidgetsFlutterBinding.ensureInitialized();
in your function before executing anything in background (in their example it write in a file every seconds)
and this library pretty much do the same see here, even better, it only start the sticky service when you need it so you don't have a notification all the time
from background_locator.
I think one of the pull request caused this.
Remove this lines from example code and let me know if it fixed the problem:
@override
void dispose() {
IsolateNameServer.removePortNameMapping('LocatorIsolate');
super.dispose();
}
from background_locator.
@mehdok I tried the above change. Still not working.
from background_locator.
After playing with I just wanted to point some problem that I'm facing right now :
if we kill FlutterActivity (in recent app) the ReceivePort is also killed so I did
if (IsolateNameServer.lookupPortByName('LocatorIsolate') != null) {
BackgroundLocator.unRegisterLocationUpdate();
IsolateNameServer.removePortNameMapping('LocatorIsolate');
}
to re-create an isolate that is sending on the port I'm listening, I don't think its a good solution since I played with ctrl + space on vs code to see what I could do with IsolateNameServer. Maybe there is something to plug the isolate on another port I don't know instead of killing it like I did.
I can't use path_provider in the callback function (I believe there isn't something like GeneratedPluginRegistrant.registerWith(flutterEngine);
in your service It would be cool to do something about it, in my case I want to write the LatLng list in a file and then when the app re-launch it fetch this file and show it on the polyline
from background_locator.
I'm not sure what is wrong with your code, But I removed those lines and the example code worked for me just fine, I still can see the logs, @viveknimkarde I moved the app to background and also removed it from recent list and the logs kept coming as usual.
@RomanJos The callback and isolate is headless and is not part of any activity, so it can continue to live without attaching to anything.
So you don't need to recreate the Isolate, It will continue to live as long as you explicitly stop it.
Beside that GeneratedPluginRegistrant.registerWith(flutterEngine);
is an old method for creating plugins, with version 2 you don't need any of that.
from background_locator.
The callback and isolate is headless and is not part of any activity, so it can continue to live without attaching to anything.
My problem is that I can't use path_provider inside the callback function, I get a NotImplemented error (This is why I pointed GeneratedPluginRegistrant
). So I'm unable to save the position in a file to retrieve it in the app. I've found this example and it look quite like this library and what I want to achieve except they are able to store the data
So you don't need to recreate the Isolate, It will continue to live as long as you explicitly stop it.
Yes but if I close the app in the recent app and then re open I will loose the port that the isolate communicate and couldn't listen and do my stuff etc. If you have a way to "retrieve" the port or create a new one and passing it to the isolate it would be perfect
And yeah I believe that this function import the native part of library so path_provider could work for example but I didn't look this much into it
from background_locator.
For the first part of your problem, right now I'm using path_provider to log into a file, look at the file_manager.dart
inside the example, and it works even when you terminate the application, I will try to update the example to make this shine a bit more :).
For the second part of the problem, I will try to handle the situation you mentioned.
from background_locator.
Yes but its not in the callback function, if you kill the app, the callback will be called and will try to send to the port without anyone listening to it and thus no log, I mean I didn't tried your example but I couldn't get any printed value from my side in the port.listen where I have one inside callback
from background_locator.
Just try the example and omit the lines i have mentioned and let me know if it is working for you or not.
Or you can share your code with me so i can have better picture of the problem.
from background_locator.
@mehdok i used example code without dispose. Logs work fine when app is in the background. But not when it is killed as mentioned by @RomanJos. Seems like callback function is sending the messages and no listeners alive to save the logs.
For my usecase Is there anyway I can use external packages like firestore or path_provider inside callback function without getting method NotImplemented error ? Or let's keep the listeners alive
from background_locator.
Related Issues (20)
- How can I send data from location callback to controller? HOT 1
- location_callback_handler.dart not found when run release project HOT 5
- [ERROR:flutter/shell/common/shell.cc(93)] Dart Error: Dart_LookupLibrary: library 'package:untitled/location_callback_handler.dart' not found. HOT 4
- Unable to build flutter release version with background_locator lastest HOT 1
- Library Update
- Issue on release build HOT 8
- Unable to capture location in release mode (Android) HOT 4
- Unable to run on iOS
- Error java.lang.IncompatibleClassChangeError: Found interface com.google.android.gms.location.FusedLocationProviderClient HOT 1
- Error on init app flutter with carp_background_location HOT 5
- java.lang.IncompatibleClassChangeError: The method 'com.google.android.gms.tasks.Task com.google.android.gms.location.FusedLocationProviderClient.requestLocationUpdates(com.google.android.gms.location.LocationRequest, com.google.android.gms.location.LocationCallback, android.os.Looper)' was expected to be of type virtual but instead was found to be of type interface (declaration of 'rekab.app.background_locator.provider.GoogleLocationProviderClient' appears in /data/app/com.doa.lojisoft.saray-JqLCd0a12SEpAYQu6cUZjg==/base.apk:classes2.dex) HOT 2
- Service stopped suddenly in release mode android
- Data type mismatch (nullable type) and method implementation error in kotlin code just after adding the dependency HOT 1
- [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument: is a regular instance: Instance of 'LocationDto'
- What is speed measured in?
- How to stop service after a period of time?
- Upgrade Background_Locator
- Need Code or Library in kotlin only
- I so confused about "getting location updates even when the app is killed" !!!!
- Is it still maintained? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from background_locator.