Fix InstantiationException on fragment

Since we overrided the empty constructor,
it can't find a empty constructor when
Fragment tries to instantiate a fragment
in framework.

So, we can't override this constructor,
and then just use newInstance() to initialize
and setup a new Fragment.

Test: robotest
Change-Id: Ifcd1c1771bc69d947caeee5c5bc055c4f94365c2
Fixes: 115676209
This commit is contained in:
tmfang
2018-10-05 18:45:07 +08:00
parent b402a56fec
commit d5405cf49d
3 changed files with 24 additions and 12 deletions

View File

@@ -51,8 +51,8 @@ public class SettingsDialogFragmentTest {
public void testGetMetrics_shouldGetMetricFromDialogCreatable() {
when(mDialogCreatable.getDialogMetricsCategory(DIALOG_ID)).thenReturn(1);
mDialogFragment =
new SettingsPreferenceFragment.SettingsDialogFragment(mDialogCreatable, DIALOG_ID);
mDialogFragment = SettingsPreferenceFragment.SettingsDialogFragment.newInstance(
mDialogCreatable, DIALOG_ID);
mDialogFragment.onAttach(RuntimeEnvironment.application);
mDialogFragment.getMetricsCategory();
@@ -65,8 +65,8 @@ public class SettingsDialogFragmentTest {
when(mDialogCreatable.getDialogMetricsCategory(DIALOG_ID)).thenReturn(-1);
try {
mDialogFragment =
new SettingsPreferenceFragment.SettingsDialogFragment(mDialogCreatable, DIALOG_ID);
mDialogFragment = SettingsPreferenceFragment.SettingsDialogFragment.newInstance(
mDialogCreatable, DIALOG_ID);
mDialogFragment.onAttach(RuntimeEnvironment.application);
fail("Should fail with IllegalStateException");
} catch (IllegalStateException e) {