Unable to switch for webview from native in Appium (version 1.4.16)


     I am using following setup:
  1. Appium version 1.4.16.

  2. API level 23

  3. Java 1.8

  4. Maven

  5. android version 6.0.1

  6. API level 23
    I have added ChromedriverHandler.jar and two methods(ChromedriverHandler.chromeDriverHandlerThread().start(),ChromedriverHandler.chromeDriverHandlerThread().stop)

    I have put for loop for context switching.it iterates 4 times,but each time different exception is throwing.But finally fails to switch.

    I am finding following problems:

    1)driver.getContextHandles(), sometimes returns webview_undefined.

    2)sometimes driver.getContextHandles() is able to retrieve context but it fails to switch.It throws context not found exception.

    3)after adding ChromedriverHandler.jar i am finding one more exception .i.eorg.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (Original error: We already have a chromedriver instance running)

Below images contain snapshot of stack trace and appium log.