title: UIAutomator testmethod passes in alternate attempts
body: <p>I have written a method in Android UIAutomator project and pushed the corresponding jar file to Android device.I am calling the method from adb shell using following command "adb shell uiautomator runtest sample.jar -c com.practice.sample.Bluetooth#turnBluetoothOFF".The problem I have is, it works only alternate times.i.e, for first attempt it works and for the second attempt it fails with Exception "Cound not register UiAutomationService" and for the third attempt it again passes.</p>
  
  <p>NOTE :
  The above thing is working fine in other Android devices( Samsung Galaxy S3 4.2.2 , Samsung Galaxy S4).I face this issue only in Samsung Galaxy S3 4.1.1 AT&amp;T mobile.  </p>
  
  <p>Any work around or solution would be needful.</p>
  
  <p>Code :</p>
  
  <pre><code>// Returns Switch object of passed Text
  </code></pre>
  
  <p>public UiObject getSwitch(String text) throws UiObjectNotFoundException {</p>
  
  <pre><code>return new UiScrollable(new UiSelector().scrollable(true))
  .getChildByText(new UiSelector().className(LinearLayout.class.getName()),text, true).getChild(
  new UiSelector().className(android.widget.Switch.class.getName()));
  
      }
  
  
  public void turnBluetoothOFF() throws UiObjectNotFoundException {
  
      if (bluetoothStatus().matches("ON")) {
          getSwitch(getValue("BluetoothText")).click();
      }
  </code></pre>
  
  <p>I feel there is nothing to do with the code. Because same code works fine in all the devices. 
      }</p>