Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to use in Android API 28 now that fragments are deprecated [duplicate]

Tags:

android

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.

like image 633
Stan Fieuws Avatar asked Oct 15 '18 20:10

Stan Fieuws


People also ask

Are fragments deprecated android?

Register and create a developer profile to keep track of sessions you're interested in by saving them to My I/O.

Are fragments still used in android?

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.

Is Fragment Manager deprecated?

Android embedding: android. app. Fragment is deprecated.

Why is it recommended to use only the default constructor to create a fragment?

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.


2 Answers

Meanwhile there's also androidx.fragment.app.Fragment,

which will supersede the android.support.v4.app.Fragment.

like image 112
Martin Zeitler Avatar answered Oct 01 '22 02:10

Martin Zeitler


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.

like image 21
Ted Hopp Avatar answered Oct 01 '22 02:10

Ted Hopp