title: Android How to avoid AccessibilityService being killed when user killed the relative application
body: <p>I use AccessibilityService to get texts durning user making click-events on other apps.According to official documents,everything goes well.
  Method 1 returns true.Method 2 returns true.
  I meet the following problem.</p>
  
  <p>The service not works when I kill the relative application manually.And the switcher still is on in system ACCESSIBILITY_SETTINGS.In this situation.Method 1 returns true.Method 2 returns false.</p>
  
  <p>I turn off the switcher in system ACCESSIBILITY_SETTINGS and turn on it again,the serivce works and Method 1 Method 2 both return true.</p>
  
  <p>I kill the relative application,turn off and turn on the switcher in system ACCESSIBILITY_SETTINGS,the service works.</p>
  
  <p>Method 1:</p>
  
  <pre><code>private boolean isAccessibilitySettingsOn(Context mContext) {
      int accessibilityEnabled = 0;
      // TestService为对应的服务
      final String service = getPackageName() + "/" + MyAccessibilityService.class.getCanonicalName();
      Log.i(TAG, "service:" + service);
      // com.z.buildingaccessibilityservices/android.accessibilityservice.AccessibilityService
      try {
          accessibilityEnabled = Settings.Secure.getInt(mContext.getApplicationContext().getContentResolver(),
                  android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
          Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled);
      } catch (Settings.SettingNotFoundException e) {
          Log.e(TAG, "Error finding setting, default accessibility to not found: " + e.getMessage());
      }
      TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
  
      if (accessibilityEnabled == 1) {
          Log.v(TAG, "***ACCESSIBILITY IS ENABLED*** -----------------");
          String settingValue = Settings.Secure.getString(mContext.getApplicationContext().getContentResolver(),
                  Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
          // com.z.buildingaccessibilityservices/com.z.buildingaccessibilityservices.TestService
          if (settingValue != null) {
              mStringColonSplitter.setString(settingValue);
              while (mStringColonSplitter.hasNext()) {
                  String accessibilityService = mStringColonSplitter.next();
  
                  Log.v(TAG, "-------------- &gt; accessibilityService :: " + accessibilityService + " " + service);
                  if (accessibilityService.equalsIgnoreCase(service)) {
                      Log.v(TAG, "We've found the correct setting - accessibility is switched on!");
                      return true;
                  }
              }
          }
      } else {
          Log.v(TAG, "***ACCESSIBILITY IS DISABLED***");
      }
      return false;
  }
  </code></pre>
  
  <p>Method 2:</p>
  
  <pre><code>public static boolean isStartAccessibilityService(Context context, String name){
      AccessibilityManager am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
      List&lt;AccessibilityServiceInfo&gt; serviceInfos = am.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_GENERIC);
      for (AccessibilityServiceInfo info : serviceInfos) {
          String id = info.getId();
          if (id.contains(name)) {
              return true;
          }
      }
      return false;
  }
  </code></pre>
  
  <p>This made user have to turn off and turn on the switcher in settings after he kill the app if he want to use the service.How to solve the problem?</p>