How to switch context to gmail app

I’m Automating an Android application with appium,
and I have to check something inside gmail, close it, then go back to my app.

while inside the gmail app, I want to close the gmail app when I’m finished.
For this I want to change the context to gmail, and use driver.closeApp().

When I ask for the driver.getContextHandles() I get:

  1. “NATIVE_APP”
  2. “WEBVIEW_com.google.android.gm”

When I then try the followings

driver.context((String) driver.getContextHandles().toArray()[1])
or
driver.context("WEBVIEW_com.google.android.gm")
or
driver.context("WEBVIEW")

I get

Method threw 'io.appium.javA_client.NoSuchContextException' exception