Skip to content

Commit 9624d34

Browse files
Fandroid745david-allison
authored andcommitted
docs: document onWebViewRecreated and onWebViewRecreatedListener
1 parent 87789dd commit 9624d34

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

AnkiDroid/src/main/java/com/ichi2/anki/previewer/CardViewerFragment.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ abstract class CardViewerFragment(
146146

147147
protected open fun onCreateWebChromeClient() = CardViewerWebChromeClient()
148148

149+
/**
150+
* Reconfigures the [WebView] after a render process crash by calling [setupWebView].
151+
*
152+
* Subclasses that override this method must call `super.onWebViewRecreated(webView)`,
153+
* as the base implementation reapplies all clients, settings, and content.
154+
*/
149155
override fun onWebViewRecreated(webView: WebView) {
150156
setupWebView(null)
151157
}

AnkiDroid/src/main/java/com/ichi2/anki/workarounds/SafeWebViewLayout.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,26 @@ open class SafeWebViewLayout :
217217
}
218218
}
219219

220+
/**
221+
* Listener for [SafeWebViewLayout.onRenderProcessGone], called after the internal [WebView] is
222+
* replaced due to a render process crash or the system killing it to free memory.
223+
*
224+
* Any [Fragment] containing a [SafeWebViewLayout] **must** implement this interface. In debug builds,
225+
* a missing implementation will throw at [SafeWebViewLayout.onAttachedToWindow()]
226+
*
227+
* @see SafeWebViewLayout.onRenderProcessGone
228+
*/
220229
fun interface OnWebViewRecreatedListener {
230+
/**
231+
* Reconfigures a [WebView] after [SafeWebViewLayout.onRenderProcessGone] has replaced
232+
* the old instance. Implementations must reapply all clients, settings and content
233+
* that were configured on the original [WebView], as [SafeWebViewLayout] only handles
234+
* the structural replacement and cannot reapply app level configuration.
235+
*
236+
* To manually trigger this path, call `webViewLayout.loadUrl("chrome://crash")`.
237+
* Automated testing requires an instrumented test; a unit test is not sufficient.
238+
*
239+
* @param webView the new [WebView], already attached to [SafeWebViewLayout]
240+
*/
221241
fun onWebViewRecreated(webView: WebView)
222242
}

0 commit comments

Comments
 (0)