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:


  • How to add Apache HTTP API (legacy) as compile-time dependency to build.grade for Android M?
  • ProgressDialog and AlertDialog cause leaked window
  • Prompt user when Back button is pressed
  • Kotlin - Intermittent “bad class file” error
  • Android - Text is Pushed to the Left in a Spinner
  • Open or see the content of a .txt with adb shell android
  • 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.

  • android: quality of the images resized in runtime
  • How to toggle orientation lock in android?
  • Android ADB stop application command like “force-stop” for non rooted device
  • Retrofit and Centralized Error Handling
  • Does it make sense to use Guice for Android
  • Android ViewPager with images: memory leak/app crashes
  • 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” WebView instances.

    This does have downsides:

    • They cannot be in the same activity, as a View from one process cannot be rendered in another process. So, if the UI metaphor for the browser implies several WebView widgets 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 OutOfMemoryError exceptions).

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.