WEB开发网
开发学院手机开发Android 开发 Android 开发教程之 Service 详解 阅读

Android 开发教程之 Service 详解

 2010-02-22 16:14:00 来源:WEB开发网   
核心提示:53. public void onClick(View arg0) {54. stopService;55. }56. });57.58. Button buttonBind = (Button) findViewById(R.id.bind_service);59. buttonBind.setOnClickLis

53. public void onClick(View arg0) {

54. stopService;

55. }

56. });

57.

58. Button buttonBind = (Button) findViewById(R.id.bind_service);

59. buttonBind.setOnClickListener(new OnClickListener {

60. public void onClick(View arg0) {

61. bindService;

62. }

63. });

64.

65. Button buttonUnbind = (Button) findViewById(R.id.unbind_service);

66. buttonUnbind.setOnClickListener(new OnClickListener {

67. public void onClick(View arg0) {

68. unbindService;

69. }

70. });

71. }

72.

73. private void startService {

74. Intent i = new Intent(this, TestService.class);

75. this.startService(i);

76. }

77.

78. private void stopService {

79. Intent i = new Intent(this, TestService.class);

80. this.stopService(i);

81. }

82.

83. private void bindService {

84. Intent i = new Intent(this, TestService.class);

85. bindService(i, _connection, Context.BIND_AUTO_CREATE);

86. _isBound = true;

87. }

88.

89. private void unbindService {

90. if (_isBound) {

91. unbindService(_connection);

92. _isBound = false;

93. }

94. }

95. }

package com.haric.tutorial;

import android.app.Activity;

import android.content.ComponentName;

import android.content.Context;

import android.content.Intent;

import android.content.ServiceConnection;

import android.os.Bundle;

import android.os.IBinder;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

上一页  1 2 3 4 5 6 7 8 9 10  下一页

Tags:Android 开发 教程

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