Git Product home page Git Product logo

Comments (11)

mehdok avatar mehdok commented on July 18, 2024 1

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.

RomanJos avatar RomanJos commented on July 18, 2024

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.

mehdok avatar mehdok commented on July 18, 2024

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.

viveknimkarde avatar viveknimkarde commented on July 18, 2024

@mehdok I tried the above change. Still not working.

from background_locator.

RomanJos avatar RomanJos commented on July 18, 2024

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.

mehdok avatar mehdok commented on July 18, 2024

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.

RomanJos avatar RomanJos commented on July 18, 2024

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.

mehdok avatar mehdok commented on July 18, 2024

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.

RomanJos avatar RomanJos commented on July 18, 2024

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.

mehdok avatar mehdok commented on July 18, 2024

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.

viveknimkarde avatar viveknimkarde commented on July 18, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.