I'm pretty new to Android development. Our teachers are telling us we should develop our app (which is a personal task) should make use of fragments. Now in API28 fragments are deprecated. Why is that exactly? What should you use now? I find a lot of different opinions on different things in Android development and as a newby it's hard to find what the good practices are.
Register and create a developer profile to keep track of sessions you're interested in by saving them to My I/O.
Here are the important things to understand about fragments: A Fragment is a combination of an XML layout file and a java class much like an Activity . Using the support library, fragments are supported back to all relevant Android versions.
Android embedding: android. app. Fragment is deprecated.
Traditionally, a Fragment instance could only be instantiated using its default empty constructor. This is because the system would need to reinitialize it under certain circumstances like configuration changes and the app's process recreation.
Meanwhile there's also androidx.fragment.app.Fragment
,
which will supersede the android.support.v4.app.Fragment
.
It's only native fragments that are being deprecated. Use the compatibility library fragments and all will be well. See this thread for more info about the difference between native and compatibility fragments. From the docs for android.app.fragment
:
This class was deprecated in API level 28.
Use the Support Library Fragment for consistent behavior across all devices and access to Lifecycle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With