Commit 9b4c6f17dbaf1dc5cd4f2baacde093c3a5f597d5
1 parent
d40aa00f
- Resume fragment if menu is clicked again
Showing
1 changed file
with
9 additions
and
4 deletions
app/src/main/java/net/devfac/userstory/MainActivity.java
... | ... | @@ -152,11 +152,16 @@ public class MainActivity extends AppCompatActivity |
152 | 152 | |
153 | 153 | public void fragmentReplace(Constants.FRAGMENT_SELECT requestedFragment){ |
154 | 154 | Fragment newFragment = getFragment(requestedFragment); |
155 | - Logger.i("Fragment Replaced to " + requestedFragment); | |
156 | 155 | |
157 | - final FragmentTransaction transaction = getFragmentManager().beginTransaction(); | |
158 | - transaction.replace(R.id.fragment_view, newFragment); | |
159 | - transaction.commit(); | |
156 | + if( getFragmentManager().findFragmentById(R.id.fragment_view) != null | |
157 | + && getFragmentManager().findFragmentById(R.id.fragment_view).equals(newFragment)){ | |
158 | + newFragment.onResume(); | |
159 | + } else { | |
160 | + Logger.i("Fragment Replaced to " + requestedFragment); | |
161 | + final FragmentTransaction transaction = getFragmentManager().beginTransaction(); | |
162 | + transaction.replace(R.id.fragment_view, newFragment); | |
163 | + transaction.commit(); | |
164 | + } | |
160 | 165 | } |
161 | 166 | |
162 | 167 | public Fragment getFragment(Constants.FRAGMENT_SELECT requestedFragment){ | ... | ... |