Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When a fragment has lost focus and then regains focus, why its onResume() method is never called in the period?

Fragment A has got focus. When Fragment B is created, B gains the focus now. This causes A to lose focus, but it is still visible. Now if B is destroyed, A gains the focus again. As A regains focus, does its onResume() method get called? If not, why?

(A and B are in the same activity.)

like image 393
Europa Avatar asked Sep 13 '12 10:09

Europa


1 Answers

The onResume() method is not called in the case you describe. Check out the documentation on the android fragment lifecycle.

onResume() is called the first time the fragment is added to the UI, and then every time it comes back from being paused. A fragment would get paused if it is added to the back stack, the user hits the home button and hides the app, or if some other app takes over the phone (e.g. the user receives a phone call.) Generally speaking, if your fragment and app are fully visible, the fragment is not being paused.

UI focus should not be confused with the activity/fragment lifecycle. The situation that you are describing seems better suited for an OnFocusChangeListener.

like image 199
zed11 Avatar answered Sep 18 '22 19:09

zed11