MainActivity:
public class MainActivity extends 活动 { ,,,Mybinder Mybinder =零; ,,,ServiceConnection mConn =, new ServiceConnection () ,,,{ ,,,,,,@Override ,,,,,,,public void onServiceDisconnected (ComponentName 名称) ,,,,,,,{ ,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,} ,,,,,,,,,,,,,,,,,,, ,,,,,,@Override ,,,,,,,public void onServiceConnected(名称、ComponentName IBinder 粘结剂) ,,,,,,,{ ,,,,,,,,,,,mybinder =, (Mybinder),粘结剂;//对象粘合剂,强转为Mybinder类型 ,,,,,,,,,,,Log.e (“MainActivity”,“mybinder.getname () "); ,,,,,,,} ,,,}; ,,,,,,,,,,,,,,, ,,@Override ,,,protected void onCreate (Bundle savedInstanceState) ,,,{ ,,,,,,,super.onCreate (savedInstanceState); ,,,,,,,setContentView (R.layout.activity_main); ,,,,,,,,,,,,,,,,,,, ,,,,,,,final TextView textView1 =, (TextView), findViewById (R.id.textView1); ,,,,,,,final TextView textView2 =, (TextView), findViewById (R.id.textView2); ,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,, ,,,,,,,findViewById R.id.button1 .setOnClickListener (OnClickListener new () ,,,,,,,{ ,,,,,,,,,,@Override ,,,,,,,,,,,public void onClick (View v) ,,,,,,,,,,,{ ,,,,,,,,,,,,,,,Intent Intent =, new 意图(MainActivity.this MyService.class); ,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,bindService (mConn,意图,还以为;BIND_AUTO_CREATE); ,,,,,,,,,,,} ,,,,,,,}); ,,,,,,,,,,,,,,,,,,, ,,,,,,,findViewById R.id.button2 .setOnClickListener (OnClickListener new () ,,,,,,,{ ,,,,,,,,,,@Override ,,,,,,,,,,,public void onClick (View v) ,,,,,,,,,,,{ ,,,,,,,,,,,,,,,unbindService (mConn); ,,,,,,,,,,,} ,,,,,,,}); ,,,,,,,,,,,,,,,,,,, ,,,,,,,findViewById R.id.button3 .setOnClickListener (OnClickListener new () ,,,,,,,{ ,,,,,,,,,,@Override ,,,,,,,,,,,public void onClick (View v) ,,,,,,,,,,,{ null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null服务初级:活动与服务间的联系,重写ServiceConnection