Giter Club home page Giter Club logo

Comments (13)

hi-dhl avatar hi-dhl commented on May 28, 2024

收到,感谢反馈,我这里尝试复现一下

from binding.

hi-dhl avatar hi-dhl commented on May 28, 2024

请修改一下使用方式,不用在构造函数中传递 layoutId,使用如下方式

class FragmentNav1 : Fragment() {
    
    // DataBinding
  	val binding: FragmentMainBinding by databind()
    
    // ViewBinding
  	 val binding: FragmentMainBinding by viewbind()
  
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        return binding.root
    }
}

from binding.

kakarrot avatar kakarrot commented on May 28, 2024

请修改一下使用方式,不用在构造函数中传递 layoutId,使用如下方式

class FragmentNav1 : Fragment() {
    
    // DataBinding
  	val binding: FragmentMainBinding by databind()
    
    // ViewBinding
  	 val binding: FragmentMainBinding by viewbind()
  
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        return binding.root
    }
}

试了一下,使用此方式bug依然存在,找了一下,发现这个链接:

https://blog.csdn.net/yechaoa/article/details/81017600

可能跟在Fragment中使用有关系,建议兼容一下

另外,这篇文章:
https://itnext.io/an-update-to-the-fragmentviewbindingdelegate-the-bug-weve-inherited-from-autoclearedvalue-7fc0a89fcae1

有更新,建议同步更新一下FragmentDelegate<T: ViewBinding> 实现

from binding.

hi-dhl avatar hi-dhl commented on May 28, 2024

@kakarrot 收到,感谢提供的方案,我研究一下,我会尽快更新版本

from binding.

hi-dhl avatar hi-dhl commented on May 28, 2024

请修改一下使用方式,不用在构造函数中传递 layoutId,使用如下方式

class FragmentNav1 : Fragment() {
    
    // DataBinding
  	val binding: FragmentMainBinding by databind()
    
    // ViewBinding
  	 val binding: FragmentMainBinding by viewbind()
  
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        return binding.root
    }
}

试了一下,使用此方式bug依然存在,找了一下,发现这个链接:

https://blog.csdn.net/yechaoa/article/details/81017600

可能跟在Fragment中使用有关系,建议兼容一下

另外,这篇文章:
https://itnext.io/an-update-to-the-fragmentviewbindingdelegate-the-bug-weve-inherited-from-autoclearedvalue-7fc0a89fcae1

有更新,建议同步更新一下FragmentDelegate<T: ViewBinding> 实现

想请问一下你的 Fragment 的版本号是多少?我这边尝试了以上文章的两种方式,均可以正常运行,可否留一个微信,想咨询一下步骤

from binding.

kakarrot avatar kakarrot commented on May 28, 2024

androidx.fragment:fragment-ktx:1.3.1

嵌套的3层fragment,最里层的fragment被动态添加/显示/隐藏,bug不是必现的,自己手机没有发生过,目前看到的都是

Firebase统计上报过来的记录,也没有固定的手机型号和Android版本,应该是在特殊情况下才能复现。

from binding.

hy-liuyuzhe avatar hy-liuyuzhe commented on May 28, 2024

我也遇到了,最后发现是网络请求回调时,界面已经销毁了,但你还使用databing对象就会必现。

from binding.

hi-dhl avatar hi-dhl commented on May 28, 2024

我也遇到了,最后发现是网络请求回调时,界面已经销毁了,但你还使用databing对象就会必现。

页面销毁的时候, binding 实例也会跟着销毁

from binding.

kakarrot avatar kakarrot commented on May 28, 2024

fragment 在 onDestroyView() 里面如果调用 binding 停止动画,释放资源的时候,binding已经为空了,所以最好的binding置null 时机应该是 onDestoryView() 执行结束后,我使用的时候改成了下面的实现

com/hi/dhl/binding/base/FragmentDelegate.kt

from binding.

hi-dhl avatar hi-dhl commented on May 28, 2024

fragment 在 onDestroyView() 里面如果调用 binding 停止动画,释放资源的时候,binding已经为空了,所以最好的binding置null 时机应该是 onDestoryView() 执行结束后,我使用的时候改成了下面的实现

com/hi/dhl/binding/base/FragmentDelegate.kt

感谢反馈,你是对的,我看了一下,确实应该在 Fragment#onDestoryView 之后进行销毁。

from binding.

hi-dhl avatar hi-dhl commented on May 28, 2024

我也遇到了,最后发现是网络请求回调时,界面已经销毁了,但你还使用databing对象就会必现。

@hy-liuyuzhe 销毁之后,如果再次使用,由于 delegate property 会被再次初始化。 这应该也是 @kakarrot 反馈的这个问题#31 (comment) 的原因,我会尽快修复这个问题

from binding.

jqorz avatar jqorz commented on May 28, 2024

Fragment中如果在lifecycleScope.launchWithCatch的onFinally回调里使用bind对象并且此时界面销毁了,还是会报错 java.lang.IllegalStateException: onGetLayoutInflater() cannot be executed until the Fragment is attached to the FragmentManager. v1.1.9

from binding.

hi-dhl avatar hi-dhl commented on May 28, 2024

Fragment中如果在lifecycleScope.launchWithCatch的onFinally回调里使用bind对象并且此时界面销毁了,还是会报错 java.lang.IllegalStateException: onGetLayoutInflater() cannot be executed until the Fragment is attached to the FragmentManager. v1.1.9

你好,可否添加我的wechat : hi-dhl, 想详细咨询一下

from binding.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.