MyService. java [java] package cn. itcast. service; import android. app. service; import android. content. intent; import android. OS. binder; import android. OS. IBinder; public class MyService extends Service {private Binder binder = new MyBinder (); public String getName (int id) {return "Chuanzhi podcast ";} @ Override public IBinder onBind (Intent intent) {return binder;} private final class MyBinder extends Binder im Plements IService {public String getName (int id) {return MyService. this. getName (23) ;}} MainActivity. java [java] package cn. itcast. service; import android. app. activity; import android. content. componentName; import android. content. intent; import android. content. serviceConnection; import android. OS. bundle; import android. OS. IBinder; import android. view. view; import android. widget. button; import Droid. widget. textView; public class MainActivity extends Activity {private MyServiceConnection conn; private IService myservice; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); conn = new MyServiceConnection (); Intent intent = new Intent (this, MyService. class); bindService (intent, conn, BIND_AUTO_CREATE); Button button = (Button) this. findViewById (R. id. button); button. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {TextView resultView = (TextView) findViewById (R. id. result); resultView. setText (myservice. getName (56) ;}});} private final class MyServiceConnection implements ServiceConnection {@ Override public void onServiceConnected (ComponentName name, IBinder service ){ Myservice = (IService) service ;}@ Override public void onServiceDisconnected (ComponentName name) {myservice = null ;}@ Override protected void onDestroy () {unbindService (conn); super. onDestroy () ;}} IService. java [java] package cn. itcast. service; public interface IService {public String getName (int id);} [html] <? Xml version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: android = "http://schemas.android.com/apk/res/android" package = "cn. itcast. service "android: versionCode =" 1 "android: versionName =" 1.0 "> <application android: icon =" @ drawable/icon "android: label = "@ string/app_name"> <activity android: name = ". mainActivity "android: label =" @ string/app_name "> <intent-filter> www.2cto.com <action android: name =" android. intent. action. MAIN "/> <category android: name =" android. intent. category. LAUNCHER "/> </intent-filter> </activity> <service android: name = ". myService "/> </application> <uses-sdk android: minSdkVersion =" 8 "/> </manifest>