0

Right now I have 2 activities. When the second activity is running, the first activity onpause is clicked which means I have to unregister all the listeners (which is not what I want when the app is running, I just wanted them unregistered when the app is in the background).

So would it make sense for me to create 2 fragments with one activity. Then I can unregister the listener when the activity onpause is called (only when app goes to background) but it won't be called when fragments are switched.

Is my understanding correct? Thank you

Snake
  • 14,228
  • 27
  • 117
  • 250

2 Answers2

1

This totally depends on the activity that you have used to launch your fragment . If two fragments A and B belong to the same activity, then the moment you switch view from Fragment A to Fragment B, your activity does not go to a paused state, means onPause() won't be called, but is still running which is ideally providing the view for Fragment B.

So, you do not need to unregister the listener on change of Fragment in the same activity.

Please correct me if I am wrong.

akash89
  • 881
  • 3
  • 12
  • 31
1

Yups Activity onPause() would not be called when switching fragments.

Rohit5k2
  • 17,948
  • 8
  • 45
  • 57