PersistedContent: Manage Waypoints for Intents

I have an issue with the PersistedContent functionality:

I want to save a Location object as a Waypoint under the following circumstances:

  1. Search the Apps existing Waypoints with an Iterator and compare them by name
  2. If the name already exists: retrieve the existing waypoint and start an Intent
  3. If the name does not exist: save a new waypoint, find it with another Iterator by name and retrieve it to start an Intent

The Problem is the second Iterator that I use is always returning null. It seems as if it is not possible to use several Iterators in the same context. Also I tried reusing the first and start the iteration from scratch in the second use case, but that does not work aswell.

Anyone experienced a similar issue with the PersistedContent iterator? And if not how are you usually handling Waypoints/Courses to start Intents for navigation?

  • Sorry, somehow the code block feature is not working in my browser, so here the code in plain text:

    var waypoint = null;
    var checkIterator = PersistedContent.getAppWaypoints();
    var currCheckWaypoint = checkIterator.next();

    // Check if Waypoint exists
    while(waypoint == null && currCheckWaypoint != null) {
    if(currCheckWaypoint.getName().equals(station["name"])) {
    waypoint = currCheckWaypoint;
    }
    currCheckWaypoint = checkIterator.next();
    }

    // Not existing create new persisted Waypoint
    if(waypoint == null) {
    var location = new Position.Location( { :latitude => station["lat"], :longitude => station["lon"], :format => :degrees } );
    PersistedContent.saveWaypoint(location, {:name => station["name"]});

    // Retrieve Waypoint again
    var iterator = PersistedContent.getAppWaypoints();
    var currWaypoint = iterator.next();
    while(waypoint == null) {
    if(currWaypoint.getName().equals(station["name"])) {
    waypoint = currWaypoint;
    }
    currWaypoint = iterator.next();
    }
    }
    System.exitTo(waypoint.toIntent());

  • I haven't run into this problem because I don't use PersistedContent in this way, but could you use a Timer.Timer() callback as a workaround? e.g.

    var waypointToOpen = null;
    function createOrSaveWaypoint() {
        // ...
        PersistedContent.saveWaypoint(location, {:name => station["name"]});
      
        waypointToOpen = station["name"];
        var timer = new Timer.Timer();
        timer.start(method(:openWaypoint), 1, false);
    }
    
    function openWaypoint() {
        var iterator = PersistedContent.getAppWaypoints();
        //... (Retrieve Waypoint with name == waypointToOpen)
        System.exitTo(waypoint.toIntent());
    }