发送消息到活动服务 - 机器人 [英] Send message from Activity to Service - Android
问题描述
我写的,而不是保持它在为Android键盘替代的应用程序,我需要,我需要在活动运行它的键盘定制化不够, InputMethodService
类。下面是我如何调用键盘我 InputMethodService
类:
I am writing a keyboard replacement app for Android, and I needed the keyboard customized enough that I need to run it in an Activity, instead of keeping it in the InputMethodService
class. Here is how I call the keyboard from my InputMethodService
class:
@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,在我的服务类,然后从活动更新它,但没有任何反应。
I have now run into the problem that I can't update the text field where the input from the keyboard should go. I tried creating a static InputConnection, in my service class, then updating it from the Activity, but nothing happens.
所以我想这里是我的问题:我能找到大量的信息如何从服务将数据发送到一个活动,但没有有关从活动将数据发送到服务(特别是输入法服务)。有谁知道如何做到这一点?
So I guess here is my question: I was able to find lots of info about how to send data from a Service to an Activity, but nothing about sending data from an Activity to a Service(specifically an input method service). Does anyone know how to do this?
推荐答案
使用的粘合剂的。
本教程的音乐播放服务是一个很好的样本的http:// www.helloandroid.com/tutorials/musicdroid-audio-player-part-ii
This tutorial about music player service is a good sample http://www.helloandroid.com/tutorials/musicdroid-audio-player-part-ii
尤其是这行
mpInterface.addSongPlaylist(file.getName());
这篇关于发送消息到活动服务 - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!