【问题标题】:Send message from Activity to Service - Android从 Activity 向服务发送消息 - Android
【发布时间】:2011-12-31 11:15:28
【问题描述】:

我正在为 Android 编写一个键盘替换应用程序,并且我需要足够定制的键盘,以便我需要在 Activity 中运行它,而不是将其保留在 InputMethodService 类中。以下是我在InputMethodService 类中调用键盘的方式:

    @Override public void onStartInputView(EditorInfo attribute, boolean restarting) {
    super.onStartInputView(attribute, restarting);

    Intent intent = new Intent(this, Keyboard.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    context.startActivity(intent);

}

我现在遇到了无法更新键盘输入应该去的文本字段的问题。我尝试在我的服务类中创建一个静态 InputConnection,然后从 Activity 更新它,但没有任何反应。

所以我想这是我的问题:我能够找到很多关于如何将数据从服务发送到活动的信息,但没有关于将数据从活动发送到服务(特别是输入法服务)的信息。有谁知道怎么做?

【问题讨论】:

    标签: android service android-activity textinput


    【解决方案1】:

    为此使用活页夹。

    这个关于音乐播放服务的教程是一个很好的例子http://www.helloandroid.com/tutorials/musicdroid-audio-player-part-ii

    尤其是这一行

    mpInterface.addSongPlaylist(file.getName());
    

    【讨论】:

    • 我们也可以使用广播将消息从活动发送到服务吗??
    猜你喜欢
    • 1970-01-01
    • 2015-08-18
    • 1970-01-01
    • 2012-05-19
    • 1970-01-01
    • 2022-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多