我创建了一个WebService
类来处理对 Web 服务的多个不同请求,这个类的广播和意图根据类key
中最初调用的方法而有所不同WebService
。我被困在如何正确处理这个问题上WebServiceReceiver
......
这是来自的重要部分WebService
:
//Broadcast the intent with data received from service call.
broadcastIntent.putExtra(broadcastIntentKeyName, response.toString());
sendBroadcast(broadcastIntent);
这是我的onReceive
:
public class WebServiceReceiver extends BroadcastReceiver
{
public WebServiceReceiver() {}
@Override
public void onReceive(Context context, Intent intent) {
Debug.waitForDebugger();
//NOTE: Not sure if i'm approaching this the right way, sure doesn't seem like it...
//Its possible that some of these will be NULL.
String GetRequestForRouteWithDriverId_DATA = intent.getStringExtra("Helper_GetRequestForRouteWithDriverId");
String StoreDataInServer_DATA = intent.getStringExtra("Helper_StoreDataInServer");
String SubmitDriverRouteData_DATA = intent.getStringExtra("Helper_SubmitDriverRouteData");
MainActivity.getInstance().updatetextViewControl(GetRequestForRouteWithDriverId_DATA);
}
}
我所拥有的确实有效,但是就像我在代码注释中提到的那样,它感觉不是正确的方法。
有没有更好的方法来解决这个问题?我只是想重新使用它onReceive
来处理所有WebService
广播。