题目内容
下面是一个需要绑定服务的Activity类程序片断,阅读程序后简述该类主要编程逻辑。public class MainActivity extends Activity implements OnClickListener {private Button bindService;private Button unbindService;private MyService.DownloadBinder downloadBinder;private ServiceConnection connection = new ServiceConnection() {@Overridepublic void onServiceDisconnected(ComponentName name) {}@Overridepublic void onServiceConnected(ComponentName name, IBinder service) {downloadBinder = (MyService.DownloadBinder) service;Log.d("MainActivity", "onServiceConnected!");downloadBinder.startDownload();downloadBinder.getProgress();}};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);bindService = (Button) findViewById(R.id.bind_service);unbindService = (Button) findViewById(R.id.unbind_service);bindService.setOnClickListener(this);unbindService.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.bind_service:Intent bindIntent = new Intent(this, MyService.class);bindService(bindIntent, connection, BIND_AUTO_CREATE);break;case R.id.unbind_service:unbindService(connection);break;default:break;}}}
查看答案
搜索结果不匹配?点我反馈
更多问题