listenzz/AndroidNavigation

AndroidX项目中,showDialog方式,onFragmentResult没有调用

AndyLeeBlue opened this issue · 13 comments

建了个简单的项目,代码都一样,只是迁移到X,就收不到返回

即将提供 androidx 版本

3.0 版本支持 androidx
implementation 'me.listenzz:navigation:3.0.0'

升级到3.0.0,但是showDialog 后 dismissDialog,onFragmentResult没有收到返回

我用 demo 测试是没有问题的呢,提供下能复现问题的代码?

`
public class AFragment extends AwesomeFragment {

public AFragment() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View root = inflater.inflate(R.layout.fragment_a, container, false);

    root.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            BFragment bFragment = new BFragment();
            showDialog(bFragment, 0);
        }
    });

    return root;
}

@Override
public void onFragmentResult(int requestCode, int resultCode, @Nullable Bundle data) {
    super.onFragmentResult(requestCode, resultCode, data);
    Log.i(TAG, "onFragmentResult");
    if (data != null) {
        String words = data.getString("text", "");
        Log.i(TAG, words);
    }
}

}
`

`
public class BFragment extends AwesomeFragment {

public BFragment() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View root = inflater.inflate(R.layout.fragment_b, container, false);

    root.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Bundle result = new Bundle();
            result.putString("text", "TEST");
            setResult(0, result);

            dismissDialog();
        }
    });

    return root;
}

}

public class MainActivity extends AwesomeActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState == null) {
        AFragment aFragment = new AFragment();
        NavigationFragment navigationFragment = new NavigationFragment();
        navigationFragment.setRootFragment(aFragment);
        setActivityRootFragment(navigationFragment);
    }

}

}
`

亲测,没有问题

Test.zip

我的AS3.3.2,打开TEST项目,onCreateView是红色的错误提示。

升级到implementation 'androidx.appcompat:appcompat:1.1.0-alpha03',之后错误消失,TEST中是alpha01版本,只有这点区别,onFragmentResult没有调用。你只修改这一个地方试试看能看到了。

对比过了,alpha01是好的,alpha03不回传。我先暂时降到alpha01用,毕竟是alpha版本,你跟着适配也麻烦,等出稳定版再适配也可以。不过文档中最好指出比较好。

已经找到原因了,底层的 DialogFragment 的某个方法签名发生了变化。

请问这个问题会在近期处理不?麻烦了

@bananaCaptain 目前兼容下面这个版本的 androidx

implementation 'androidx.appcompat:appcompat:1.0.2'

现在 4.1.0 支持 androidx.appcompat:appcompat:1.1.0