{"action":"created","issue":{"url":"https://api.github.com/repos/e-mission/e-mission-data-collection/issues/36","labels_url":"https://api.github.com/repos/e-mission/e-mission-data-collection/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/e-mission/e-mission-data-collection/issues/36/comments","events_url":"https://api.github.com/repos/e-mission/e-mission-data-collection/issues/36/events","html_url":"https://github.com/e-mission/e-mission-data-collection/issues/36","id":93177750,"number":36,"title":"SharedPreferences are sometimes not saved properly","user":{"login":"shankari","id":2423263,"avatar_url":"https://avatars.githubusercontent.com/u/2423263?v=3","gravatar_id":"","url":"https://api.github.com/users/shankari","html_url":"https://github.com/shankari","followers_url":"https://api.github.com/users/shankari/followers","following_url":"https://api.github.com/users/shankari/following{/other_user}","gists_url":"https://api.github.com/users/shankari/gists{/gist_id}","starred_url":"https://api.github.com/users/shankari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shankari/subscriptions","organizations_url":"https://api.github.com/users/shankari/orgs","repos_url":"https://api.github.com/users/shankari/repos","events_url":"https://api.github.com/users/shankari/events{/privacy}","received_events_url":"https://api.github.com/users/shankari/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2015-07-06T03:22:12Z","updated_at":"2015-09-23T04:34:23Z","closed_at":null,"body":"It looks like SharedPreferences do not save properly in some cases.\r\nHere's what I saw from the app logs for a trip in which I left Tied House at 8:30pm and came home.\r\nThe app appeared to have been killed and relaunched by the geofence exit, since the id was 9.\r\n\r\n    [9|1435807867723|7/1/15 8:31 PM|FINE]TripDiaryStateMachineReceiver : after reading from the prefs, the current state is local.state.waiting_for_trip_start\r\n\r\nAfter processing the geofence exit, the new state was ongoing_trip.\r\n\r\n    [14|1435807867853|7/1/15 8:31 PM|FINE]TripDiaryStateMachineReceiver : newState after handling action is local.state.ongoing_trip\r\n\r\nHowever, when the state is next read, it is still waiting_for_trip_start\r\n\r\n    [87|1435808413146|7/1/15 8:40 PM|FINE]TripDiaryStateMachineReceiver : after reading from the prefs, the current state is local.state.waiting_for_trip_start\r\n\r\nSo when the trip end is detected, we think that the current state is already waiting_for_trip_start,\r\nso we do not turn off ongoing tracking, and we do not establish the geofence."},"comment":{"url":"https://api.github.com/repos/e-mission/e-mission-data-collection/issues/comments/142487475","html_url":"https://github.com/e-mission/e-mission-data-collection/issues/36#issuecomment-142487475","issue_url":"https://api.github.com/repos/e-mission/e-mission-data-collection/issues/36","id":142487475,"user":{"login":"shankari","id":2423263,"avatar_url":"https://avatars.githubusercontent.com/u/2423263?v=3","gravatar_id":"","url":"https://api.github.com/users/shankari","html_url":"https://github.com/shankari","followers_url":"https://api.github.com/users/shankari/followers","following_url":"https://api.github.com/users/shankari/following{/other_user}","gists_url":"https://api.github.com/users/shankari/gists{/gist_id}","starred_url":"https://api.github.com/users/shankari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shankari/subscriptions","organizations_url":"https://api.github.com/users/shankari/orgs","repos_url":"https://api.github.com/users/shankari/repos","events_url":"https://api.github.com/users/shankari/events{/privacy}","received_events_url":"https://api.github.com/users/shankari/received_events","type":"User","site_admin":false},"created_at":"2015-09-23T04:34:22Z","updated_at":"2015-09-23T04:34:22Z","body":"Actually, this is probably a result of (2) above.\r\nThis stackoverflow answer (http://stackoverflow.com/questions/15524280/service-vs-intentservice)\r\nlinked to the source code of IntentService\r\nhttps://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/app/IntentService.java\r\nwhich is pretty clear.\r\n\r\nOnce the `onHandleIntent()` is completed, `stopSelf()` is called.\r\nThis means that any async tasks launched from `onHandleIntent()` are not guaranteed to finish.\r\n\r\nWill fix this by using a standard service instead of an `IntentService` and calling `stopSelf` from the `setNewState` method to ensure that we wait until the state is set before the service is terminated."}}