{"action":"created","issue":{"url":"https://api.github.com/repos/BoltsFramework/Bolts-Android/issues/37","labels_url":"https://api.github.com/repos/BoltsFramework/Bolts-Android/issues/37/labels{/name}","comments_url":"https://api.github.com/repos/BoltsFramework/Bolts-Android/issues/37/comments","events_url":"https://api.github.com/repos/BoltsFramework/Bolts-Android/issues/37/events","html_url":"https://github.com/BoltsFramework/Bolts-Android/issues/37","id":49723617,"number":37,"title":"Question: how to handle activity rotation / re-creation lifecycle with Tasks?","user":{"login":"danielesegato","id":469948,"avatar_url":"https://avatars.githubusercontent.com/u/469948?v=3","gravatar_id":"","url":"https://api.github.com/users/danielesegato","html_url":"https://github.com/danielesegato","followers_url":"https://api.github.com/users/danielesegato/followers","following_url":"https://api.github.com/users/danielesegato/following{/other_user}","gists_url":"https://api.github.com/users/danielesegato/gists{/gist_id}","starred_url":"https://api.github.com/users/danielesegato/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielesegato/subscriptions","organizations_url":"https://api.github.com/users/danielesegato/orgs","repos_url":"https://api.github.com/users/danielesegato/repos","events_url":"https://api.github.com/users/danielesegato/events{/privacy}","received_events_url":"https://api.github.com/users/danielesegato/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-11-21T17:20:40Z","updated_at":"2015-01-19T21:57:35Z","closed_at":null,"body":"Hi,\r\n\r\nThis is not a bug, nor a feature request. This is a question.\r\n\r\nBolts seems a very nice library, but I do not really understand how you pictured its usage along with the Android lifecycle.\r\n\r\nSuppose I do obtain a Task:\r\n\r\n    Task<MyResult> myTask = ....;\r\n\r\nNow I want to somehow link that task to my UI (show a spinner before showing the result or things like this).\r\n\r\nI have to maintain that task across activity recreation.\r\n\r\n* Placing it in static variable is bad practice.\r\n* I can create a Loader, but then why do I need a task? My loader will just wait for the result and give me it\r\n* I can associate my task to the ApplicationContext (instead of the activity) and modify the database or a shared preference and update the UI: it's a lot more work then with a loader that does the thing\r\n\r\nI'm sure you considered this while developing bolts, how am I supposed to retain the Task, or at least a callback to it across activity instances (destroy/recreate cycle)?\r\n\r\nThanks\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/BoltsFramework/Bolts-Android/issues/comments/70568566","html_url":"https://github.com/BoltsFramework/Bolts-Android/issues/37#issuecomment-70568566","issue_url":"https://api.github.com/repos/BoltsFramework/Bolts-Android/issues/37","id":70568566,"user":{"login":"JosephEarl","id":2513147,"avatar_url":"https://avatars.githubusercontent.com/u/2513147?v=3","gravatar_id":"","url":"https://api.github.com/users/JosephEarl","html_url":"https://github.com/JosephEarl","followers_url":"https://api.github.com/users/JosephEarl/followers","following_url":"https://api.github.com/users/JosephEarl/following{/other_user}","gists_url":"https://api.github.com/users/JosephEarl/gists{/gist_id}","starred_url":"https://api.github.com/users/JosephEarl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JosephEarl/subscriptions","organizations_url":"https://api.github.com/users/JosephEarl/orgs","repos_url":"https://api.github.com/users/JosephEarl/repos","events_url":"https://api.github.com/users/JosephEarl/events{/privacy}","received_events_url":"https://api.github.com/users/JosephEarl/received_events","type":"User","site_admin":false},"created_at":"2015-01-19T21:57:35Z","updated_at":"2015-01-19T21:57:35Z","body":"I would not say this issue is anything in particular to do with the concept of Tasks or their implementation.\r\n\r\n# Option 1\r\nRun the task in a retained fragment. This is the general guidance from the Android team for operations that are closely connected to the UI (i.e. that only run where there is a UI). See http://developer.android.com/guide/topics/resources/runtime-changes.html#RetainingAnObject\r\nThe fragment will then need to call back to the Activity.\r\n\r\n# Option 2\r\nDon't run Tasks or asynchronous methods in your Activity context. Run them in your Application context or Service context and use an Event Bus to send events to your UI components.\r\n\r\n"}}