Return to Simple HTTP service HTTPServiceStarter
1: package com.voipplus.mmsclient.httpService;
2:
3: import android.content.ComponentName;
4: import android.content.Context;
5: import android.content.;
6: import android.content.ServiceConnection;
7: import android.os.IBinder;
8: import android.util.Log;
9:
10: public class HTTPServiceStarter {
11: private static final String TAG = "HTTPServiceStarter";
12: private HTTPService httpService;
13: private boolean isBound = false;
14: private Context context;
15: private HTTPServiceConnectionListener listener;
16:
17: public interface HTTPServiceConnectionListener {
18: void onHTTPServiceConnected(HTTPService service);
19: }
20:
21: public HTTPServiceStarter(Context context, HTTPServiceConnectionListener listener) {
22: this.context = context;
23: this.listener = listener;
24: }
25:
26: private ServiceConnection connection = new ServiceConnection() {
27: @Override
28: public void onServiceConnected(ComponentName className, IBinder service) {
29: HTTPService.LocalBinder binder = (HTTPService.LocalBinder) service;
30: httpService = binder.getService();
31: isBound = true;
32: Log.d(TAG, "HTTPService connected");
33: if (listener != null) {
34: listener.onHTTPServiceConnected(httpService);
35: }
36: }
37:
38: @Override
39: public void onServiceDisconnected(ComponentName arg0) {
40: isBound = false;
41: Log.d(TAG, "HTTPService disconnected");
42: }
43: };
44:
45: public void bind() {
46: intent = new (context, HTTPService.class);
47: context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
48: }
49:
50: public void unbind() {
51: if (isBound) {
52: context.unbindService(connection);
53: isBound = false;
54: }
55: }
56:
57: public void startAndBindService() {
58: intent = new (context, HTTPService.class);
59: context.startService(intent);
60: context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
61: }
62: }
63:
Return to Simple HTTP service
AndroidMosaic context:
Comments (
)
)
Link to this page:
http://www.vb-net.com/AndroidMosaic/HTTPServiceStarter.htm
|
|