手柄上的onActivityResult服务 [英] Handle onActivityResult on a Service
问题描述
所以我有一个简单的问题,它可能处理方法的onActivityResult()的服务如果此活动是由相同的服务指南(使用意向)?
So i have a simple Question , it is Possible to Handle the Method onActivityResult() in a Service if this Activity was Started from the Same Service (Using Intent) ?
在我的情况,我要开始SpeechRegnition,说话,获取对服务的结果,一切都在后台(主要服务从开始一个Widget),
In My Case , i want to start SpeechRegnition , Speak , and Get the Result on the Service , Everything on Background (Main Service Start from a Widget) ,
感谢。
推荐答案
您可以将指针从活动范围内传递到活动相关服务并启动另一个活动在那里。
You can pass the pointer to activity to a service and start another activity out there from the activity context.
在从中您将收到的结果使这样的一个活动:
In an activity from which you will receive the result make something like this:
private static Activity activity;
public static Activity getActivity() {
return activity;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activity = this;
}
实现的onActivityResult那里,做的方式向结果传递给无论是LocalBroadcastManager或静态字段,或粘合剂服务 - 无论适合你。
Implement onActivityResult out there and make a way to pass the result to a service either by LocalBroadcastManager or static fields, or Binder - whatever suits you.
这时从服务呼叫
TheActivity.getActivity().startActivityForResult(...
这篇关于手柄上的onActivityResult服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!