Fixed
Status Update
Comments
ku...@google.com <ku...@google.com>
ku...@google.com <ku...@google.com> #2
Thank you for reporting this issue. For us to further investigate this issue, please provide the following additional information:
Steps to reproduce
Please provide a sample application or apk to reproduce the issue.
Also kindly mention the steps to be followed for reproducing the issue with the given sample application.
Steps to reproduce
Please provide a sample application or apk to reproduce the issue.
Also kindly mention the steps to be followed for reproducing the issue with the given sample application.
ku...@google.com <ku...@google.com> #3
Please provide the information as requested in comment #2 , For us to further investigate this issue.
ku...@google.com <ku...@google.com> #4
We are closing this issue as we don't have enough actionable information. If you are still facing this problem, please open new issue and add the relevant information along with reference to earlier issue.
sm...@gmail.com <sm...@gmail.com> #5
I'm not sure who decided there isn't enough information. The description contains the exact steps to reproduce the bug.
However if you follow the instructions here:https://developer.android.com/guide/topics/ui/dialogs#CustomLayout you also will hit this bug.
Basically the android x dialog fragment has the hook to call onCreateDialog in a callback to the layout inflater. However, accessing the layout inflater recursively triggers onCreateDialog...
However if you follow the instructions here:
Basically the android x dialog fragment has the hook to call onCreateDialog in a callback to the layout inflater. However, accessing the layout inflater recursively triggers onCreateDialog...
sm...@gmail.com <sm...@gmail.com> #6
The bug is essentially in Fragment:
LayoutInflater performGetLayoutInflater(@Nullable Bundle savedInstanceState) {
LayoutInflater layoutInflater = onGetLayoutInflater(savedInstanceState);
mLayoutInflater = layoutInflater;
return mLayoutInflater;
}
Because the layout inflator is not "set" invoking the callback onGetLayoutInflator() which is where onCreateDialog() is invoked will cause the cycle to repeat if you call getLayoutInflater in onCreateDialog()
The fix should be just reordering the code to set the inflater before invoking the callback.
LayoutInflater performGetLayoutInflater(@Nullable Bundle savedInstanceState) {
mLayoutInflater = layoutInflater;
LayoutInflater layoutInflater = onGetLayoutInflater(savedInstanceState);
return mLayoutInflater;
}
LayoutInflater performGetLayoutInflater(@Nullable Bundle savedInstanceState) {
LayoutInflater layoutInflater = onGetLayoutInflater(savedInstanceState);
mLayoutInflater = layoutInflater;
return mLayoutInflater;
}
Because the layout inflator is not "set" invoking the callback onGetLayoutInflator() which is where onCreateDialog() is invoked will cause the cycle to repeat if you call getLayoutInflater in onCreateDialog()
The fix should be just reordering the code to set the inflater before invoking the callback.
LayoutInflater performGetLayoutInflater(@Nullable Bundle savedInstanceState) {
mLayoutInflater = layoutInflater;
LayoutInflater layoutInflater = onGetLayoutInflater(savedInstanceState);
return mLayoutInflater;
}
sm...@gmail.com <sm...@gmail.com> #7
Actually that doesn't work, a better solution is to not hook onCreateDialog into the onGetLayoutInflater callback... but there is a nasty dependency between DialogFragment and Fragment that I don't have time to try and resolve.
il...@google.com <il...@google.com> #8
Using requireActivity().layoutInflater as is done in the Java code sample in the docs is one workaround until this can be fixed.
af...@gmail.com <af...@gmail.com> #9
I just wound up using the following as a work around:
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
dialogView = LayoutInflater.from(context).inflate(R.layout.fragment_add_user, null)
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
dialogView = LayoutInflater.from(context).inflate(R.layout.fragment_add_user, null)
jp...@gmail.com <jp...@gmail.com> #10
I uncovered this issue as well. I am working on migrating my app to use androidx fragments instead of framework. This includes migrating custom DialogFragments. Previously I was using LayoutInflater.from(context) also; I guess that's the only way to do it via framework fragments, maybe there's no "getLayoutInflater" on the fragment there.
Do you need any further samples to investigate?
Do you need any further samples to investigate?
il...@google.com <il...@google.com>
an...@google.com <an...@google.com> #11
ap...@google.com <ap...@google.com> #12
Project: platform/frameworks/support
Branch: androidx-master-dev
commit cd5549fdd847601c65d3a0e6f72a7de83c61154c
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Mar 09 13:00:19 2020
Allow calling getLayoutInflater in onCreateDialog
Calling getLayoutInflater in a custom DialogFragment's overridden
onCreateDialog method causes a StackOverflowError because
DialogFragment's onGetLayoutInflater relied on calling onCreateDialog.
In onCreateDialog, we should return the layout inflater from the
Fragment onGetLayoutInflater instead, which has no idea about the
context or theme of the Dialog. The layout inflater returned in
onCreateView will remain the same, but the two will be different.
This also fixes an issue where FragmentContainerView and the fragment
tag cannot inflate fragments within a DialogFragment. The inflated
fragments are properly added to the DialogFragment's
childFragmentManager.
Test: Added DialogFragmentInflatedChildTest test
Bug: 117894767
RelNote: "Fixed a bug in DialogFragment that caused a StackOverflowError
when calling getLayoutInflater from within onCreateDialog."
Change-Id: Ib55b53de9ccd5ccb69111d519fd7ec02fbf9726e
M fragment/fragment/build.gradle
M fragment/fragment/src/androidTest/AndroidManifest.xml
A fragment/fragment/src/androidTest/java/androidx/fragment/app/DialogFragmentInflatedChildTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/DialogFragment.java
https://android-review.googlesource.com/1253912
Branch: androidx-master-dev
commit cd5549fdd847601c65d3a0e6f72a7de83c61154c
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Mar 09 13:00:19 2020
Allow calling getLayoutInflater in onCreateDialog
Calling getLayoutInflater in a custom DialogFragment's overridden
onCreateDialog method causes a StackOverflowError because
DialogFragment's onGetLayoutInflater relied on calling onCreateDialog.
In onCreateDialog, we should return the layout inflater from the
Fragment onGetLayoutInflater instead, which has no idea about the
context or theme of the Dialog. The layout inflater returned in
onCreateView will remain the same, but the two will be different.
This also fixes an issue where FragmentContainerView and the fragment
tag cannot inflate fragments within a DialogFragment. The inflated
fragments are properly added to the DialogFragment's
childFragmentManager.
Test: Added DialogFragmentInflatedChildTest test
Bug: 117894767
RelNote: "Fixed a bug in DialogFragment that caused a StackOverflowError
when calling getLayoutInflater from within onCreateDialog."
Change-Id: Ib55b53de9ccd5ccb69111d519fd7ec02fbf9726e
M fragment/fragment/build.gradle
M fragment/fragment/src/androidTest/AndroidManifest.xml
A fragment/fragment/src/androidTest/java/androidx/fragment/app/DialogFragmentInflatedChildTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/DialogFragment.java
jb...@google.com <jb...@google.com> #13
This has been fixed internally and will be available in both the Fragment 1.2.3 release and 1.3.0-alpha02 release.
Description
Please describe the problem in detail. Be sure to include:
- Steps to reproduce the problem (including sample code if appropriate).
Subclass androidx.fragment.app.DialogFragment and in onCreateDialog get an instance of the layout inflater using getLayoutInflater.
compileSdkVersion 28
minSdkVersion 23
targetSdkVersion 28
import android.app.AlertDialog
import android.app.Dialog
import android.os.Bundle
import androidx.fragment.app.DialogFragment
class AddUserDialogFragment : DialogFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val inflater = layoutInflater // this throws a stack overflow error
val view = inflater.inflate(R.layout.fragment_add_user, null)
return AlertDialog.Builder(activity!!)
.setTitle(R.string.some_title)
.setView(view)
.setPositiveButton(R.string.add, null)
.setNegativeButton(R.string.cancel) { dialog, which ->
}
.create()
}
}
- What happened.
The call to getLayoutInflater stack overflows
2018-10-18 06:55:31.279 20850-20850/? E/AndroidRuntime: at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1308)
at androidx.fragment.app.Fragment.getLayoutInflater(Fragment.java:1293)
at com.ase.solutions.mat.organization.adduser.AddUserDialogFragment.onCreateDialog(AddUserDialogFragment.kt:26)
at androidx.fragment.app.DialogFragment.onGetLayoutInflater(DialogFragment.java:330)
at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1308)
at androidx.fragment.app.Fragment.getLayoutInflater(Fragment.java:1293)
at com.ase.solutions.mat.organization.adduser.AddUserDialogFragment.onCreateDialog(AddUserDialogFragment.kt:26)
at androidx.fragment.app.DialogFragment.onGetLayoutInflater(DialogFragment.java:330)
at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1308)
at androidx.fragment.app.Fragment.getLayoutInflater(Fragment.java:1293)
.. further down ...
2018-10-18 06:55:31.279 20850-20850/? E/AndroidRuntime: at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1308)
at com.ase.solutions.mat.organization.adduser.AddUserDialogFragment.onCreateDialog(AddUserDialogFragment.kt:26)
at androidx.fragment.app.DialogFragment.onGetLayoutInflater(DialogFragment.java:330)
at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1308)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
at androidx.fragment.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
- What you think the correct behavior should be.
It should return a layout inflater
Don't forget to mention which version of Android you're using, and/or which
device the problem appears on (model and Android version).
API 28
Please also run "adb bugreport" and archive the output.