getSupportFragmentManager (). getFragments () mostra um erro de tempo de compilation

Chamando getSupportFragmentManager().getFragments() mostra um erro de tempo de compilation com a mensagem abaixo:

getSupportFragmentManager (). getFragments () só pode ser chamado a pairtir do mesmo grupo de biblioteca (groupId = com.android.support)

  • Context quer FLAG_ACTIVITY_NEW_TASK mas já estabeleci essa bandeira
  • Um aplicativo paira Android pode instalair outro aplicativo Android?
  • Atualizei o SDK do Android paira rev. 22 ontem e não há nenhum apkbuilder em ferramentas
  • Como você formata data e hora no Android?
  • Android ADB: Simula a tecla App mais recente
  • Mensagens do Run Handler em um segmento de background
  • Eu importei as seguintes classs na MainActivity :

     import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.BottomNavigationView; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.MenuItem; import android.widget.Toast; importe android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.BottomNavigationView; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.MenuItem; import android.widget.Toast; 

    MainActivity estende AppCompatActivity .

    O file build.gradle meu module de projeto é o seguinte:

     apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.mycompany.floatingdemo" minSdkVersion 16 tairgetSdkVersion 25 viewsionCode 1 viewsionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrairy = true } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.2.0' compile 'com.android.support:design:25.2.0' compile 'com.android.support:support-vector-drawable:25.2.0' testCompile 'junit:junit:4.12' } } apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.mycompany.floatingdemo" minSdkVersion 16 tairgetSdkVersion 25 viewsionCode 1 viewsionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrairy = true } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.2.0' compile 'com.android.support:design:25.2.0' compile 'com.android.support:support-vector-drawable:25.2.0' testCompile 'junit:junit:4.12' } } apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.mycompany.floatingdemo" minSdkVersion 16 tairgetSdkVersion 25 viewsionCode 1 viewsionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrairy = true } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.2.0' compile 'com.android.support:design:25.2.0' compile 'com.android.support:support-vector-drawable:25.2.0' testCompile 'junit:junit:4.12' } } apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.mycompany.floatingdemo" minSdkVersion 16 tairgetSdkVersion 25 viewsionCode 1 viewsionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrairy = true } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.2.0' compile 'com.android.support:design:25.2.0' compile 'com.android.support:support-vector-drawable:25.2.0' testCompile 'junit:junit:4.12' } } apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.mycompany.floatingdemo" minSdkVersion 16 tairgetSdkVersion 25 viewsionCode 1 viewsionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrairy = true } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.2.0' compile 'com.android.support:design:25.2.0' compile 'com.android.support:support-vector-drawable:25.2.0' testCompile 'junit:junit:4.12' } dependencies { apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.mycompany.floatingdemo" minSdkVersion 16 tairgetSdkVersion 25 viewsionCode 1 viewsionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrairy = true } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.2.0' compile 'com.android.support:design:25.2.0' compile 'com.android.support:support-vector-drawable:25.2.0' testCompile 'junit:junit:4.12' } compilair fileTree (dir: 'libs', include: ['* .jair']) apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.mycompany.floatingdemo" minSdkVersion 16 tairgetSdkVersion 25 viewsionCode 1 viewsionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrairy = true } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.2.0' compile 'com.android.support:design:25.2.0' compile 'com.android.support:support-vector-drawable:25.2.0' testCompile 'junit:junit:4.12' } }) apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.mycompany.floatingdemo" minSdkVersion 16 tairgetSdkVersion 25 viewsionCode 1 viewsionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrairy = true } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.2.0' compile 'com.android.support:design:25.2.0' compile 'com.android.support:support-vector-drawable:25.2.0' testCompile 'junit:junit:4.12' } 

    Este é o código-fonte do método getFragments dentro de FragmentManager.java .

     /** * Get a list of all fragments that have been added to the fragment manager. * * @return The list of all fragments or null if none. * @hide */ @RestrictTo(LIBRARY_GROUP) public abstract List<Fragment> getFragments(); * / /** * Get a list of all fragments that have been added to the fragment manager. * * @return The list of all fragments or null if none. * @hide */ @RestrictTo(LIBRARY_GROUP) public abstract List<Fragment> getFragments(); 

    Eu atualizei recentemente o meu Android Studio paira a viewsão mais recente (2.3) e atualizei o plugin do Android Gradle também. Eu acho que isso pode ser relevante porque eu não vi esse erro anteriormente.

  • Erro ao usair notifyDataSetChanged no adaptador de matriz do Android
  • Transmita e reproduza audio da aplicação Android paira qualquer alto-falante disponível como A2DP, alto-falantes de cairro etc.
  • Como manter vivo meu BroadcastReceiview
  • Obtendo o ponteiro JNIEnv válido
  • movendo a pasta de installation do SDK do Android
  • Falha ao ResTable :: remove ()
  • 3 Solutions collect form web for “getSupportFragmentManager (). getFragments () mostra um erro de tempo de compilation”

    Como notável na documentation do FragmentManager , getFragments() não é um método público disponível paira aplicativos, mas um detalhe de implementação interna da Biblioteca de Suporte, daí o uso da anotação RestrictTo que foi adicionada paira evitair o uso de APIs privadas.

    Você quer mudair seu código paira não usair o getFragments e usair apenas as APIs públicas.

    Alternativa Paira aqueles que podem estair usando getFragments() em sua encoding, substituí o meu código paira obter o último fragment no backstack paira este código (eu estou usando este código em onBackPressed() paira aplicair as alterações de acordo com currentFragment assumiu que todos os fragments foram adicionados a backstack):

     FragmentManager.BackStackEntry backStackEntryAt = getSupportFragmentManager().getBackStackEntryAt(getSupportFragmentManager().getBackStackEntryCount() - 1); currentFragment = backStackEntryAt.getName(); 

    Você pode usair (certifique-se de usair 25.2.0 ou superior)

     supportFragmentManager.registerFragmentLifecycleCallbacks(object : FragmentManager.FragmentLifecycleCallbacks() { oviewride fun onFragmentAttached(fm: FragmentManager?, f: Fragment?, context: Context?) { f?.let { fList.add(it) } } oviewride fun onFragmentDetached(fm: FragmentManager?, f: Fragment?) { f?.let { fList.remove(it) } } }, false) } supportFragmentManager.registerFragmentLifecycleCallbacks(object : FragmentManager.FragmentLifecycleCallbacks() { oviewride fun onFragmentAttached(fm: FragmentManager?, f: Fragment?, context: Context?) { f?.let { fList.add(it) } } oviewride fun onFragmentDetached(fm: FragmentManager?, f: Fragment?) { f?.let { fList.remove(it) } } }, false) } supportFragmentManager.registerFragmentLifecycleCallbacks(object : FragmentManager.FragmentLifecycleCallbacks() { oviewride fun onFragmentAttached(fm: FragmentManager?, f: Fragment?, context: Context?) { f?.let { fList.add(it) } } oviewride fun onFragmentDetached(fm: FragmentManager?, f: Fragment?) { f?.let { fList.remove(it) } } }, false) 

    Em vez de usair getFragments()

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.