I have an AndroidView as a part of a LazyColumn Item
But when i navigate i can see thats its released and is recreated again when i navigate back
Anyone knows how to fix this?
z
Zach Klippenstein (he/him) [MOD]
05/27/2024, 5:02 PM
What behavior do you expect?
v
Vaibhav Jaiswal
05/28/2024, 8:46 AM
My AndroidView has a WebView in it
Due to this it loads the webpage again when I navigate to a different screen and come back
Vaibhav Jaiswal
05/28/2024, 8:46 AM
as it is released and recreated again
s
Sergey Y.
05/28/2024, 10:44 AM
That approach won't work because navigating away from the screen will dispose and release it. I believe it'll behave the same way with fragments and the navigation library since fragments get replaced and destroyed by default. You need to rethink the layout architecture. Maybe try caching the WebView content after it's loaded and reusing it.
I'd suggest preserving the data but not the view, as that's generally recommended.
v
Vaibhav Jaiswal
05/28/2024, 10:45 AM
I have the html string preserved
But as the webview is released and recreated it loads it again
Same thing also happens when this WebView is in a LazyColumn