Private Browsing is deprecated in Android WebView as of API 17. What is the alternative?
The API specification reads as follows for the WebView constructor that allows private browsing to be enabled:
WebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing)
This constructor was deprecated in API level 17. Private browsing is no longer supported directly via WebView and will be removed in a future release. Prefer using WebSettings, WebViewDatabase, CookieManager and WebStorage for fine-grained control of privacy data.
As of API 19 (KitKat) private browsing is disabled. Attempting to invoke this constructor with a value of true results in an IllegalArgumentException.
The alternatives suggested will not be even marginally effective in replicating the behavior of private browsing. The CookieManager class is a singleton, with all settings being applied to the entire application. There is no “fine grained control of privacy data” with this approach. The only control provided by CookieManager is the ability to disable cookies altogether, for EVERY WebView present in the app. This change means that third-party browsers are no longer able to replicate the private browsing feature of Google’s own browser in any capacity.
I’d greatly appreciate any suggestions for working around this behavior. As of yet I can find nothing in the API that would make any resemblance of the former private browsing capability possible.
One Solution collect form web for “Private Browsing is deprecated in Android WebView as of API 17. What is the alternative?”
In addition to what I have in the comment, this is another place where having multiple processes is justified. Since
CookieManager is a singleton, separate processes will have separate
CookieManager instances. “Private browsing”
WebView instances could be in a separate process from the “regular browsing”
This does have downsides:
They cannot be in the same activity, as a
Viewfrom one process cannot be rendered in another process. So, if the UI metaphor for the browser implies several
WebViewwidgets in a single activity (e.g., tabs), that UI metaphor will need to be tweaked to allow for “context switching” between regular and private browsing.
This will consume more system RAM, which is bad for the user, albeit good for the developer (less likelihood of