The problem because I am working not with only with activities, but also with nested fragments (inside activities). I have tried to use onKeyDown event, onBackPressed. I have tried different approaches, but some of them required a lot of checks, others doesn't work at all. I need this, because someone can accidentally click back button more than one time and this will close the app and in case of low memory it will be killed after that because now it is not in foreground. If C has set the "I'm Destroying" flag, then don't perform the request.I am trying to implement confirm message to exit from my app. Have C pass some flag up to the controlling activity (we'll call it Main), move the async call up, and when B wants to do the web request, have it call up to main to do so. If this is null you could then assume that the operation in action is the destruction. When onResume is called you could do a getFragmentByTag on the fragment which has already been destroyed. Have you determined what other lifecycle methods are being called - if it's only on resume, then move the async call further down in the lifecyle (onCreateView or onAttach for example) so that it's only called when moving through it in the normal manner. Note: I'm using the latest compatibility/support library. In this case how can I detect if the entire backstack is being collapsed and skip the async web request on Fragment B in the OnResume method? Note: I'd still want the async web request to execute if Fragment B is popped/displayed by using the Back button. For Fragment B, I don't want the async web request to trigger since its going to be immediately destroyed/removed after its popped (because the entire backstack is being cleared). As each fragment is popped the fragment's onResume method is called. When PopBackStackImmediate is called it pops the Fragments off one by one until the stack is cleared. Fragment B tries to make a async web request when its onResume is method is called.įragment C has a button called "Clear Backstack" that clears the backstack by calling popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |