2011-05-15 64 views
0

所以我試圖綁定一個服務與我的應用程序,我想知道是否有可能綁定到每一個單一的活動(一個服務到10個活動)。綁定服務快速問題

感謝, 阿伯爾

回答

0

是的,你其實應該使用每個活動相同的代碼:

public class YourActivity extends Activity { 
@Override public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    bindService(new Intent(), new ServiceConnection(){ 
     @Override 
     public void onServiceConnected(ComponentName arg0, IBinder arg1) { 
     } 
     @Override 
     public void onServiceDisconnected(ComponentName arg0) { 
     } 
    }, Context.BIND_AUTO_CREATE); 
} 
}