Activity, AppCompatActivity, FragmentActivity, and ActionBarActivity: When to Use Which?

I thought Activity was deprecated No. So for API Level 22 (with a minimum support for API Level 15 or 16), what exactly should I use both to host the components, and for the components themselves? Are there uses for all of these, or should I be using one or two almost exclusively? Activity is … Read more

IllegalStateException: Can not perform this action after onSaveInstanceState with ViewPager

Please check my answer here. Basically I just had to : Don’t make the call to super() on the saveInstanceState method. This was messing things up… This is a known bug in the support package. If you need to save the instance and add something to your outState Bundle you can use the following: In the end the proper solution was (as seen in the … Read more

findViewById in Fragment

Use getView() or the View parameter from implementing the onViewCreated method. It returns the root view for the fragment (the one returned by onCreateView() method). With this you can call findViewById(). As getView() works only after onCreateView(), you can’t use it inside onCreate() or onCreateView() methods of the fragment .

Why fragments, and when to use fragments instead of activities?

#1 & #2 what are the purposes of using a fragment & what are the advantages and disadvantages of using fragments compared to using activities/views/layouts? Fragments are Android’s solution to creating reusable user interfaces. You can achieve some of the same things using activities and layouts (for example by using includes). However; fragments are wired … Read more

How do popBackStack() and replace() operations differ?

replace() does 2 things: Remove currently added fragment (A) from the container (C) you indicated Add new fragment (B) to the same container These 2 operations are what is saved as a Backstack record / transaction. Note that fragment A remains in created state, and its view is destroyed. Now popBackStack() reverses your last transaction that you’ve added to BackStack. … Read more