4

We can read in official Android doc

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.This class was deprecated in API level 28.

What is going on ?
What we should use now instead of Fragments and DialogFragments ?

purcha
  • 371
  • 3
  • 12
  • 5
    Possible duplicate of [Fragments deprecated in Android P](https://stackoverflow.com/questions/49446411/fragments-deprecated-in-android-p) – Ernest Zamelczyk Oct 01 '18 at 10:28
  • 1
    android.app.Fragment and android.app.DialogFragment is deprecated in API 28, use android.support.v4.app.Fragment and android.support.v4.app.DialogFragment. – Shamsul Oct 01 '18 at 10:32

2 Answers2

3

You have to change the import statement only.

From : android.app.Fragment To: android.support.v4.app.Fragment

That's it

Parul
  • 387
  • 1
  • 5
0

Now,You can use Fragment Support library (AndroidX) from Android P(28).

Add following in gradle.properties

android.useAndroidX=true
android.enableJetifier=true 

Add following dependency in project build.gradle

implementation 'androidx.fragment:fragment:1.0.0'

Change import statement from

Fragment: import android.app.Fragment;

DialogFragment: import android.app.DialogFragment;

TO

Fragment: import androidx.fragment.app.Fragment;

DialogFragment: androidx.fragment.app.DialogFragment;

Reference link provided by Google: https://developer.android.com/jetpack/androidx/migrate

Ronak Mehta
  • 5,971
  • 5
  • 42
  • 69