0

Base on this question, how can I init variable in Fragment1 when I navigate to it. Let's say

Fragment1 has mCount(int) which I want it to be 0 every time I navigate to Fragment1.

Because in Fragment1, it will have the event that change the variable mCount.

And Fragment1 will not calling onCreateView if I go Fragment0 and Fragment1 back and forth.

I cannot find the way to init variable because fragment will get position 2 which is Fragment2.

Thank you in advance for any help or any suggestions.

Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
barssala
  • 463
  • 2
  • 6
  • 22
  • why will it not be calling onCreateView? – joao86 Sep 06 '17 at 16:43
  • It's not going to call onCreateView on Fragment0 and Fragment1 when I go back and forth between two of them. It will call onCreateView of Fragment2. – barssala Sep 06 '17 at 16:46
  • I was going to tell you to send it in the Bundle when you opened Fragment1 but if it won't call onCreateView then there is no use. – joao86 Sep 06 '17 at 16:53
  • See linked duplicate. In your case, instead of using the `sendGetRequest()` method, define your method in the Fragment as `reInitCount()`, and re-initialize the count inside that method. – Daniel Nugent Sep 06 '17 at 18:12

0 Answers0