Android 系统服务侦听器是否已本地化到我的应用实例



我正在使用SDK中的示例代码作为示例编写拼写检查客户端。我有以下代码(不是实际实现,而是准确的示例表示):

public class HelloSpellChecker implements SpellCheckerSessionListener {
    private SpellCheckerSession mSpellCheckService;
    private void bindService() {
        final TextServicesManager tsm = (TextServicesManager) getSystemService(
            Context.TEXT_SERVICES_MANAGER_SERVICE);
        mSpellCheckService = tsm.newSpellCheckerSession(null, null, this, true);
    }        
    public void getSuggestions(String word) {
        mSpellCheckService.getSuggestions(new TextInfo("tgis"), 3);
    }
    @Override
    public void onGetSentenceSuggestions(final SentenceSuggestionsInfo[] arg0) {
        Log.d(TAG, "onGetSentenceSuggestions");
        // Process suggestions
    }
}

我想知道的是,onGetSentenceSuggestions只会在我的应用程序调用getSuggestions时触发,还是会在系统服务收到getSuggestions请求时触发?

如果是后者,确保我的应用仅处理它请求的建议的最佳方法是什么?

在这种情况下,

我会说Android系统服务侦听器是通过会话本地化的。onGetSentenceSuggestions 方法由任何请求 getSuggestions 方法触发。但是,您不必担心处理应用请求的建议,因为拼写检查器会话会处理它。你的应用仅获取你的应用创建的会话请求的建议,以便与拼写检查器服务进行交互。希望这有帮助。

引用:

  • http://developer.android.com/reference/android/view/textservice/SpellCheckerSession.html
  • http://developer.android.com/guide/topics/text/spell-checker-framework.html

最新更新