Skip to content

fix(#539): finish the CookieSyncManager removal by calling CookieManager.flush()#1350

Draft
jim-daf wants to merge 1 commit intoQuantumBadger:masterfrom
jim-daf:fix/issue-539-cookiemanager-flush-on-destroy
Draft

fix(#539): finish the CookieSyncManager removal by calling CookieManager.flush()#1350
jim-daf wants to merge 1 commit intoQuantumBadger:masterfrom
jim-daf:fix/issue-539-cookiemanager-flush-on-destroy

Conversation

@jim-daf
Copy link
Copy Markdown

@jim-daf jim-daf commented Apr 26, 2026

Closes #539.

Context

Issue #539 reported that CookieSyncManager is deprecated since API 21 and is no longer required. The legacy call is already gone from master, but the modern half of the contract is still missing. The Android docs make the new pattern explicit:

Apps targeting API level 21 or above should call CookieManager.flush() to ensure that cookies are written to persistent storage.

Without that call the recently issued removeAllCookies() request is only queued and may be lost when the fragment tears down its WebView and the OS later reclaims the process.

Fix

Add the explicit flush() call inside WebViewFragment.onDestroyView() so the cookie store is durably written before the fragment finishes destruction. A short comment records the rationale so future contributors do not reintroduce CookieSyncManager.

// CookieSyncManager was removed in favour of CookieManager flush()
// for API 21 plus, see https://developer.android.com/reference/android/webkit/CookieManager#flush()
final CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookies(null);
cookieManager.flush();

Validation

  • The diff only adds two comment lines and one method call inside the same onDestroyView() block.
  • flush() has been part of the WebView public API since API 21, which matches the project's existing minSdkVersion.
  • Manual smoke test: open the in-app browser, navigate, then back out. The next launch starts with a clean cookie store as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CookieSyncManager is not needed from API 21

1 participant