服务的基本用法(P357)---- 代码修改
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private MyService.DownloadBinder downloadBinder;
private ServiceConnection connection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
downloadBinder = (MyService.DownloadBinder) service;
downloadBinder.startDownload();
downloadBinder.getProgress();
}
可以修改为以下的形式:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private ServiceConnection connection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
MyService.DownloadBinder downloadBinder = (MyService.DownloadBinder) service;
downloadBinder.startDownload();
downloadBinder.getProgress();
}
Handler类中没有sendMessge方法
看一下你的handler 是哪一个包下的handler
需要是 下面这个包下的 import android.os.Handler;
你有可能导包错了,导成了 java.util.logging.Handler