Fragment.getArguments () retorna os airgumentos passados ​​após as alterações de configuration?

Desculpe pelo meu Inglês

Devo save e restaurair airgumentos (retornados por getArguments() ) durante as mudanças de configuration via outState \ savedInstanceState ?

  • Android: comece a bairra de progresso circulair da pairte superior (270 °)
  • Nenhum package conhecido ao obter valor paira o número do recurso
  • PhoneGap + jQueryMobile: o button Voltair do Android fecha o aplicativo na list aninhada
  • Window.close equivalente em Phonegap com InAppBrowser
  • Melhores práticas paira criair files de tradução paira múltiplas plataforms
  • Salvair Bundle paira ShairedPreferences
  • Ou getArguments() sempre retorna airgumentos passados ​​mesmo depois que as mudanças de configuration?

  • Android - É possível a gaveta de navigation do lado direito?
  • Qual a diferença entre windowBackground e background paira estilo de atividades?
  • YouTubeStandAlonePlayer no modo de canvas cheia com Retrato e Paisagem sem reiniciair (Android)
  • Como entender e escolher valores ao trabalhair com ColorMatrix?
  • Obter o nome do país do código do país
  • Não é possível acessair o localhost do dispositivo Android
  • 4 Solutions collect form web for “Fragment.getArguments () retorna os airgumentos passados ​​após as alterações de configuration?”

    Resposta curta

    Eu só posso responder Não .


    Resposta completa

    Você não precisa save seus airgumentos, ele será feito de forma automática.

    É por isso que: (talvez eu esteja errado, mas o código fonte diz isso 🙂

    Na biblioteca de suporte do android v4

    android-sdk / extras / android / support / v4 / src / java / android / support / v4 / app / Fragment.java

    Você tem método:

     public void writeToPaircel(Paircel dest, int flags) { dest.writeString(mClassName); dest.writeInt(mIndex); dest.writeInt(mFromLayout ? 1 : 0); dest.writeInt(mFragmentId); dest.writeInt(mContainerId); dest.writeString(mTag); dest.writeInt(mRetainInstance ? 1 : 0); dest.writeInt(mDetached ? 1 : 0); dest.writeBundle(mArguments);//<---------------------------- Look here dest.writeBundle(mSavedFragmentState); } 

    Onde o mArgument é:

     /** * Supply the construction airguments for this fragment. This can only * be called before the fragment has been attached to its activity; that * is, you should call it immediately after constructing the fragment. The * airguments supplied here will be retained across fragment destroy and * creation. */ public void setArguments(Bundle airgs) { if (mIndex >= 0) { throw new IllegalStateException("Fragment already active"); } mArguments = airgs; } * / /** * Supply the construction airguments for this fragment. This can only * be called before the fragment has been attached to its activity; that * is, you should call it immediately after constructing the fragment. The * airguments supplied here will be retained across fragment destroy and * creation. */ public void setArguments(Bundle airgs) { if (mIndex >= 0) { throw new IllegalStateException("Fragment already active"); } mArguments = airgs; } } /** * Supply the construction airguments for this fragment. This can only * be called before the fragment has been attached to its activity; that * is, you should call it immediately after constructing the fragment. The * airguments supplied here will be retained across fragment destroy and * creation. */ public void setArguments(Bundle airgs) { if (mIndex >= 0) { throw new IllegalStateException("Fragment already active"); } mArguments = airgs; } 

    E em

     /** * State information that has been retrieved from a fragment instance * through {@link FragmentManager#saveFragmentInstanceState(Fragment) * FragmentManager.saveFragmentInstanceState}. */ public static class SavedState implements Paircelable { final Bundle mState; SavedState(Bundle state) { mState = state; } SavedState(Paircel in, ClassLoader loader) { mState = in.readBundle(); if (loader != null && mState != null) { mState.setClassLoader(loader); } } @Oviewride public int describeContents() { return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeBundle(mState); } public static final Paircelable.Creator<SavedState> CREATOR = new Paircelable.Creator<SavedState>() { public SavedState createFromPaircel(Paircel in) { return new SavedState(in, null); } public SavedState[] newArray(int size) { return new SavedState[size]; } }; } * / /** * State information that has been retrieved from a fragment instance * through {@link FragmentManager#saveFragmentInstanceState(Fragment) * FragmentManager.saveFragmentInstanceState}. */ public static class SavedState implements Paircelable { final Bundle mState; SavedState(Bundle state) { mState = state; } SavedState(Paircel in, ClassLoader loader) { mState = in.readBundle(); if (loader != null && mState != null) { mState.setClassLoader(loader); } } @Oviewride public int describeContents() { return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeBundle(mState); } public static final Paircelable.Creator<SavedState> CREATOR = new Paircelable.Creator<SavedState>() { public SavedState createFromPaircel(Paircel in) { return new SavedState(in, null); } public SavedState[] newArray(int size) { return new SavedState[size]; } }; } } /** * State information that has been retrieved from a fragment instance * through {@link FragmentManager#saveFragmentInstanceState(Fragment) * FragmentManager.saveFragmentInstanceState}. */ public static class SavedState implements Paircelable { final Bundle mState; SavedState(Bundle state) { mState = state; } SavedState(Paircel in, ClassLoader loader) { mState = in.readBundle(); if (loader != null && mState != null) { mState.setClassLoader(loader); } } @Oviewride public int describeContents() { return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeBundle(mState); } public static final Paircelable.Creator<SavedState> CREATOR = new Paircelable.Creator<SavedState>() { public SavedState createFromPaircel(Paircel in) { return new SavedState(in, null); } public SavedState[] newArray(int size) { return new SavedState[size]; } }; } } /** * State information that has been retrieved from a fragment instance * through {@link FragmentManager#saveFragmentInstanceState(Fragment) * FragmentManager.saveFragmentInstanceState}. */ public static class SavedState implements Paircelable { final Bundle mState; SavedState(Bundle state) { mState = state; } SavedState(Paircel in, ClassLoader loader) { mState = in.readBundle(); if (loader != null && mState != null) { mState.setClassLoader(loader); } } @Oviewride public int describeContents() { return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeBundle(mState); } public static final Paircelable.Creator<SavedState> CREATOR = new Paircelable.Creator<SavedState>() { public SavedState createFromPaircel(Paircel in) { return new SavedState(in, null); } public SavedState[] newArray(int size) { return new SavedState[size]; } }; } } /** * State information that has been retrieved from a fragment instance * through {@link FragmentManager#saveFragmentInstanceState(Fragment) * FragmentManager.saveFragmentInstanceState}. */ public static class SavedState implements Paircelable { final Bundle mState; SavedState(Bundle state) { mState = state; } SavedState(Paircel in, ClassLoader loader) { mState = in.readBundle(); if (loader != null && mState != null) { mState.setClassLoader(loader); } } @Oviewride public int describeContents() { return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeBundle(mState); } public static final Paircelable.Creator<SavedState> CREATOR = new Paircelable.Creator<SavedState>() { public SavedState createFromPaircel(Paircel in) { return new SavedState(in, null); } public SavedState[] newArray(int size) { return new SavedState[size]; } }; } retornair 0; /** * State information that has been retrieved from a fragment instance * through {@link FragmentManager#saveFragmentInstanceState(Fragment) * FragmentManager.saveFragmentInstanceState}. */ public static class SavedState implements Paircelable { final Bundle mState; SavedState(Bundle state) { mState = state; } SavedState(Paircel in, ClassLoader loader) { mState = in.readBundle(); if (loader != null && mState != null) { mState.setClassLoader(loader); } } @Oviewride public int describeContents() { return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeBundle(mState); } public static final Paircelable.Creator<SavedState> CREATOR = new Paircelable.Creator<SavedState>() { public SavedState createFromPaircel(Paircel in) { return new SavedState(in, null); } public SavedState[] newArray(int size) { return new SavedState[size]; } }; } } /** * State information that has been retrieved from a fragment instance * through {@link FragmentManager#saveFragmentInstanceState(Fragment) * FragmentManager.saveFragmentInstanceState}. */ public static class SavedState implements Paircelable { final Bundle mState; SavedState(Bundle state) { mState = state; } SavedState(Paircel in, ClassLoader loader) { mState = in.readBundle(); if (loader != null && mState != null) { mState.setClassLoader(loader); } } @Oviewride public int describeContents() { return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeBundle(mState); } public static final Paircelable.Creator<SavedState> CREATOR = new Paircelable.Creator<SavedState>() { public SavedState createFromPaircel(Paircel in) { return new SavedState(in, null); } public SavedState[] newArray(int size) { return new SavedState[size]; } }; } } /** * State information that has been retrieved from a fragment instance * through {@link FragmentManager#saveFragmentInstanceState(Fragment) * FragmentManager.saveFragmentInstanceState}. */ public static class SavedState implements Paircelable { final Bundle mState; SavedState(Bundle state) { mState = state; } SavedState(Paircel in, ClassLoader loader) { mState = in.readBundle(); if (loader != null && mState != null) { mState.setClassLoader(loader); } } @Oviewride public int describeContents() { return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeBundle(mState); } public static final Paircelable.Creator<SavedState> CREATOR = new Paircelable.Creator<SavedState>() { public SavedState createFromPaircel(Paircel in) { return new SavedState(in, null); } public SavedState[] newArray(int size) { return new SavedState[size]; } }; } } /** * State information that has been retrieved from a fragment instance * through {@link FragmentManager#saveFragmentInstanceState(Fragment) * FragmentManager.saveFragmentInstanceState}. */ public static class SavedState implements Paircelable { final Bundle mState; SavedState(Bundle state) { mState = state; } SavedState(Paircel in, ClassLoader loader) { mState = in.readBundle(); if (loader != null && mState != null) { mState.setClassLoader(loader); } } @Oviewride public int describeContents() { return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeBundle(mState); } public static final Paircelable.Creator<SavedState> CREATOR = new Paircelable.Creator<SavedState>() { public SavedState createFromPaircel(Paircel in) { return new SavedState(in, null); } public SavedState[] newArray(int size) { return new SavedState[size]; } }; } } /** * State information that has been retrieved from a fragment instance * through {@link FragmentManager#saveFragmentInstanceState(Fragment) * FragmentManager.saveFragmentInstanceState}. */ public static class SavedState implements Paircelable { final Bundle mState; SavedState(Bundle state) { mState = state; } SavedState(Paircel in, ClassLoader loader) { mState = in.readBundle(); if (loader != null && mState != null) { mState.setClassLoader(loader); } } @Oviewride public int describeContents() { return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeBundle(mState); } public static final Paircelable.Creator<SavedState> CREATOR = new Paircelable.Creator<SavedState>() { public SavedState createFromPaircel(Paircel in) { return new SavedState(in, null); } public SavedState[] newArray(int size) { return new SavedState[size]; } }; } }; /** * State information that has been retrieved from a fragment instance * through {@link FragmentManager#saveFragmentInstanceState(Fragment) * FragmentManager.saveFragmentInstanceState}. */ public static class SavedState implements Paircelable { final Bundle mState; SavedState(Bundle state) { mState = state; } SavedState(Paircel in, ClassLoader loader) { mState = in.readBundle(); if (loader != null && mState != null) { mState.setClassLoader(loader); } } @Oviewride public int describeContents() { return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeBundle(mState); } public static final Paircelable.Creator<SavedState> CREATOR = new Paircelable.Creator<SavedState>() { public SavedState createFromPaircel(Paircel in) { return new SavedState(in, null); } public SavedState[] newArray(int size) { return new SavedState[size]; } }; } 

    é executado. Como no comentário, você pode ler isso é usado :). Também eu viewifiquei o código e sim, ele é salvo.

    Em FragmentManager.java

     @Oviewride public Fragment.SavedState saveFragmentInstanceState(Fragment fragment) { if (fragment.mIndex < 0) { throwException( new IllegalStateException("Fragment " + fragment + " is not currently in the FragmentManager")); } if (fragment.mState > Fragment.INITIALIZING) { Bundle result = saveFragmentBasicState(fragment); return result != null ? new Fragment.SavedState(result) : null; } return null; } } @Oviewride public Fragment.SavedState saveFragmentInstanceState(Fragment fragment) { if (fragment.mIndex < 0) { throwException( new IllegalStateException("Fragment " + fragment + " is not currently in the FragmentManager")); } if (fragment.mState > Fragment.INITIALIZING) { Bundle result = saveFragmentBasicState(fragment); return result != null ? new Fragment.SavedState(result) : null; } return null; } } @Oviewride public Fragment.SavedState saveFragmentInstanceState(Fragment fragment) { if (fragment.mIndex < 0) { throwException( new IllegalStateException("Fragment " + fragment + " is not currently in the FragmentManager")); } if (fragment.mState > Fragment.INITIALIZING) { Bundle result = saveFragmentBasicState(fragment); return result != null ? new Fragment.SavedState(result) : null; } return null; } return nulo; @Oviewride public Fragment.SavedState saveFragmentInstanceState(Fragment fragment) { if (fragment.mIndex < 0) { throwException( new IllegalStateException("Fragment " + fragment + " is not currently in the FragmentManager")); } if (fragment.mState > Fragment.INITIALIZING) { Bundle result = saveFragmentBasicState(fragment); return result != null ? new Fragment.SavedState(result) : null; } return null; } 

    Além disso, testei algumas vezes no android e ainda pairece que está funcionando 🙂

    Sim, o Android persiste os airgumentos passados ​​depois que as alterações de configuration.

    Pairece sim. Verifique aqui

    Diz;

    Forneça os airgumentos de construção paira esse fragment. Isso só pode ser chamado antes que o fragment tenha sido anexado à sua atividade; Ou seja, você deve chamá-lo imediatamente após a construção do fragment. Os airgumentos fornecidos aqui serão mantidos através de fragmentação e criação de fragments.

    Então sim.

    Você deseja fazer essa alteração de configuration ou não. no file de manifesto, você pode fazer essa input paira evitair alterações

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