WEB开发网
开发学院手机开发Android 开发 android service 学习 阅读

android service 学习

 2010-08-23 01:13:00 来源:WEB开发网   
核心提示:46 if (!mediaPlayer.isPlaying()) {47 mediaPlayer.start();48 }49 }5051 @Override52 public void pause() throws RemoteException {53 Log.d(TAG,"pause...."

46 if (!mediaPlayer.isPlaying()) {

47 mediaPlayer.start();

48 }

49 }

50

51 @Override

52 public void pause() throws RemoteException {

53 Log.d(TAG,"pause....");

54

55 if (mediaPlayer != null && mediaPlayer.isPlaying()) {

56 mediaPlayer.pause();

57 }

58 }

59

60 };

61

62

63 @Override

64 public void onDestroy() {

65 super.onDestroy();

66

67 Log.d(TAG, "onDestroy");

68 if(mediaPlayer != null){

69 mediaPlayer.stop();

70 mediaPlayer.release();

71 }

72 }

73}

当客户端应用连接到这个Service时,onServiceConnected方法将被调用,客户端就可以获得IBinder对象。参看下面的客户端onServiceConnected方法:

view sourceprint?01private ServiceConnection sc = new ServiceConnection() {

02

03 @Override

04 public void onServiceDisconnected(ComponentName name) {

05 musicService = null;

06 Log.d(TAG, "in onServiceDisconnected");

07 }

08

09 @Override

10 public void onServiceConnected(ComponentName name, IBinder service) {

11 musicService = IMusicControlService.Stub.asInterface(service);

12 Log.d(TAG, "in onServiceConnected");

13 }

14 };

启动后的界面如下

上一页  5 6 7 8 9 10 

Tags:android service 学习

编辑录入:coldstar [复制链接] [打 印]
赞助商链接