I am trying to do something using boolean in the Fragment class every time a Fragment displayed.
Example
My application launches, opens FirstFragment and boolean for the first time always true , then I have an if clause that checks its value:
if (FirstTime) { FirstTime = false; } else { // Other stuff here, cause it not true. }
Then, for the first time, FirstTime is true , I do something like go to another Fragment . and when I get back to Fragment1 and on my onCreate() , I will do the same. It is always true , it seems that it is refreshing or something like that.
Then I thought that this might be a problem with Fragment , and every time I click on Fragment1 , it restarts or something like that. Then I added getter and setter to my MainActivity :
public Boolean getFirstTime() { return FirstTime; } public void setFirstTime(Boolean FirstTime) { this.FirstTime = FirstTime; }
where from the start, it's true, and then I changed the code from Fragment1 to:
if (((MainActivity) getActivity()).getFirstTime()) ((MainActivity) getActivity()).setFirstTime(false); } else { // Other stuff here, cause it not true, }
However, he is still talking about it.
What am I doing wrong or what did I misunderstand about fragments?
Is there any way to do this?
java android android-lifecycle sharedpreferences android-fragments
Skizo-ozᴉʞS May 2 '15 at 19:40 2015-05-02 19:40
source share