Comments (10)
add ViewBindingPropertyDelegate.strictMode = false
in Application#onCreate
Maybe the author forgot what he wrote .
from viewbindingpropertydelegate.
May be it's normal you've checked , But app creash . Why throw an exception? shouldn't do anything.
from viewbindingpropertydelegate.
@Reginer , I need a sample where the issue is reproducible
from viewbindingpropertydelegate.
After activity destroy ,binding.textView.setText
from viewbindingpropertydelegate.
I've checked the behavior and it's normal. After Lifecycle became DESTROYED viewbinding keep last creataed version.
from viewbindingpropertydelegate.
from viewbindingpropertydelegate.
Oh , strictMode default value should be false.
from viewbindingpropertydelegate.
It's not connected with StrictMode. It's part of normal flow now to work with ViewBinding when view isn't exist
from viewbindingpropertydelegate.
Hi @kirich1409
I have the same problem in my app:
class HomeActivity : FragmentActivity() {
private val binding: ActivityHomeBinding by viewBinding()
override fun onDestroy() {
binding.list.adapter = null // crash happens here
super.onDestroy()
}
}
With list
being a RecyclerView
.
And the stacktrace:
Caused by java.lang.IllegalStateException: Access to viewBinding after Lifecycle is destroyed or hasn't created yet. The instance of viewBinding will be not cached.
at by.kirich1409.viewbindingdelegate.LifecycleViewBindingProperty.runStrictModeChecks(ViewBindingProperty.kt:112)
at by.kirich1409.viewbindingdelegate.LifecycleViewBindingProperty.getValue(ViewBindingProperty.kt:91)
at by.kirich1409.viewbindingdelegate.LifecycleViewBindingProperty.getValue(ViewBindingProperty.kt:71)
at net.foobar.ui.home.HomeActivity.getBinding(HomeActivity.kt:31)
at net.foobar.ui.home.HomeActivity.onDestroy(HomeActivity.kt:174)
at android.app.Activity.performDestroy(Activity.java:8063)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1341)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4926)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4970)
at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:44)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
As the documentation in Lifecycle.State.DESTROYED
says:
this state is reached right before Activity's onDestroy call.
So technically the Activity is not destroyed yet, and its views neither. So I think the runStrictModeChecks()
in ViewBindingProperty.getValue() is wrong.
What do you think about it?
from viewbindingpropertydelegate.
@cdongieux , sadly, but it can be normal. Destroy in the VИЗВ associated with Lifecycle, not with Activity lifecycle callbacks. It's better to use
private val binding: ActivityHomeBinding by viewBinding(onViewDestroyed = {...})
from viewbindingpropertydelegate.
Related Issues (20)
- java.lang.IllegalStateException Fragment's view can't be accessed. Fragment isn't added HOT 1
- IllegalStateException when using viewBinding for onCreateView HOT 14
- Can give a sample of how to use RecyclerView.ViewHolder? HOT 1
- IllegalStateException: Fragment's view can't be accessed. HOT 6
- IllegalStateException FragmentViewBindingProperty.getLifecycleOwner HOT 1
- UnresolvedReference HOT 2
- Crash on language change HOT 7
- Android Studio Dolphin | 2021.3.1 does not show layout preview HOT 2
- IllegalStateException: Fragment's view can't be accessed. Fragment isn't added. - when trying to restore fragment state HOT 1
- Kkk
- Custom views are crashing preview after updating Android Studio up to Dolphin HOT 1
- Hgf
- Version 1.5.8 onwards causes error in RecyclerView HOT 1
- NoClassDefFoundError HOT 1
- Clear happens after onViewCreated HOT 3
- Generic type cannot be used HOT 5
- how to use 'noreflection:1.5.6' in this case? HOT 3
- Random crash when navigating between fragments back and forth. HOT 3
- Is it possible to provide support for viewBinding(ViewBinding::inflate) HOT 2
- java.lang.IllegalStateException: Fragment's view can't be accessed HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from viewbindingpropertydelegate.