{"action":"created","issue":{"url":"https://api.github.com/repos/konmik/nucleus/issues/76","repository_url":"https://api.github.com/repos/konmik/nucleus","labels_url":"https://api.github.com/repos/konmik/nucleus/issues/76/labels{/name}","comments_url":"https://api.github.com/repos/konmik/nucleus/issues/76/comments","events_url":"https://api.github.com/repos/konmik/nucleus/issues/76/events","html_url":"https://github.com/konmik/nucleus/issues/76","id":139990044,"number":76,"title":"Possible solution for view recycling and destroying the Presenter in Fragments.","user":{"login":"ShlMlkzdh","id":11231195,"avatar_url":"https://avatars.githubusercontent.com/u/11231195?v=3","gravatar_id":"","url":"https://api.github.com/users/ShlMlkzdh","html_url":"https://github.com/ShlMlkzdh","followers_url":"https://api.github.com/users/ShlMlkzdh/followers","following_url":"https://api.github.com/users/ShlMlkzdh/following{/other_user}","gists_url":"https://api.github.com/users/ShlMlkzdh/gists{/gist_id}","starred_url":"https://api.github.com/users/ShlMlkzdh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ShlMlkzdh/subscriptions","organizations_url":"https://api.github.com/users/ShlMlkzdh/orgs","repos_url":"https://api.github.com/users/ShlMlkzdh/repos","events_url":"https://api.github.com/users/ShlMlkzdh/events{/privacy}","received_events_url":"https://api.github.com/users/ShlMlkzdh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-03-10T19:46:31Z","updated_at":"2016-04-05T23:19:42Z","closed_at":null,"body":"Hi,\r\n\r\nIn the [View recycling and view stack](https://github.com/konmik/konmik.github.io/wiki/Introduction-to-Model-View-Presenter-on-Android#view-recycling-and-view-stack) section of your [Introduction to Model View Presenter on Android](https://github.com/konmik/konmik.github.io/wiki/Introduction-to-Model-View-Presenter-on-Android), you mention that \r\n\r\n> A fragment can not know if it is detached because of configuration change or because it is being popped off the stack.\r\n\r\nI've been trying different ways to solve this issue and came across the [Fragment#isRemoving()](http://developer.android.com/reference/android/app/Fragment.html#isRemoving()) method. I think if we replace `Activity#isFinishing() ` with `Activity#isFinishing()  || Fragment#isRemoving()` then we can destroy the `Presenter` attached to the `Fragment` safely.\r\n\r\n@konmik, please let me know if this is a viable solution (at least in the case of a `Fragment`.)\r\n\r\nThanks."},"comment":{"url":"https://api.github.com/repos/konmik/nucleus/issues/comments/206030301","html_url":"https://github.com/konmik/nucleus/issues/76#issuecomment-206030301","issue_url":"https://api.github.com/repos/konmik/nucleus/issues/76","id":206030301,"user":{"login":"rlac","id":1572523,"avatar_url":"https://avatars.githubusercontent.com/u/1572523?v=3","gravatar_id":"","url":"https://api.github.com/users/rlac","html_url":"https://github.com/rlac","followers_url":"https://api.github.com/users/rlac/followers","following_url":"https://api.github.com/users/rlac/following{/other_user}","gists_url":"https://api.github.com/users/rlac/gists{/gist_id}","starred_url":"https://api.github.com/users/rlac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rlac/subscriptions","organizations_url":"https://api.github.com/users/rlac/orgs","repos_url":"https://api.github.com/users/rlac/repos","events_url":"https://api.github.com/users/rlac/events{/privacy}","received_events_url":"https://api.github.com/users/rlac/received_events","type":"User","site_admin":false},"created_at":"2016-04-05T23:19:42Z","updated_at":"2016-04-05T23:19:42Z","body":"I think this commit will miss destroying Presenters for Fragment's that are destroyed while on the back stack, as it only does the check during onPause.\r\n\r\nMy previous comment was going from memory, I looked back at some past projects and I do the check and destroy the Presenter in the Fragment's onDestroy, not onPause.\r\n\r\nWhile a Fragment is on the back stack it's paused, but not removed. It can be removed + destroyed while on the back stack without ever going through another resume/pause cycle (it's onDestroy will always be called though). A couple of cases I know where this can happen if the back stack it's on is destroyed (e.g. replace in a transaction with no addToBackStack) or the Activity is destroyed."}}