Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRyan Huai
6,665 Pointsfragment not from support library still works properly. Why?
According to the video, in order to make the back button works properly, activity and fragment should be either both from appcomat library or both from support library. But the fragment in my code does not use support library and back button still works. Can somebody explain why?
follows are the code from MainActivity: package teamtreehouse.com.smellslikebakin;
import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements ListFragment.OnRecipeSelectedInterface{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//when app is rotated, the fragment will be automatically created, hence, no need to create again.
ListFragment savedFragment = (ListFragment) getFragmentManager().findFragmentById(R.id.placeHolder);
if (savedFragment == null ) {
ListFragment fragment = new ListFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.placeHolder, fragment);
fragmentTransaction.commit();
}
}