刷新片段不再起作用 [英] Refresh fragment not working any more

查看:94
本文介绍了刷新片段不再起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天失去了一些时间,因为我的功能代码不再工作了. 更新到支持库25.1.0的新版本后,重新加载片段视图的代码不再起作用:

I lost some hours today because my functionaly code were not working any more. The code to reload the view of a fragment was not working anymore after updating to the new version of Support Library 25.1.0:

这是我的代码:

FragmentManager manager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = manager.beginTransaction();
fragmentTransaction.detach(fragment);
fragmentTransaction.attach(fragment);
fragmentTransaction.commit();

我试图调试在

public void onPause()
public void onStop()
public void onAttach(Context context)
public void onDetach()  
public void onDestroyView()
public void onDestroy()

但是该应用程序未执行任何该功能,并且屏幕上没有任何反应.

but the application is not entering into any of that function and nothing happened on the screen.

如果我单独调用detach而不进行附加,则应用程序将输入onPause和onStop,然后视图离开屏幕.

If I call detach alone, without attach, the application enter in onPause and onStop and the view leave the screen.

推荐答案

我发现自己也遇到了同样的问题,但没有找到在线答案.最后,我发现在支持库的版本25.1.1中,对片段事务进行了一些优化. (请参见 https://developer.android. com/topic/libraries/support-library/revisions.html#25-1-1 ).为您的交易禁用这些交易将使其按预期运行:

I've found myself facing the same issue, and found no answer online. Finally I've found out that some optimizations were added to Fragment Transactions in Revision 25.1.1 of the Support Library. (see https://developer.android.com/topic/libraries/support-library/revisions.html#25-1-1). Disabling those for your transaction will make it work as expected:

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.setAllowOptimization(false);
transaction.detach(fragment).attach(fragment).commitAllowingStateLoss();

更新

setAllowOptimization已过时.改为使用setReorderingAllowed.

这篇关于刷新片段不再起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆