开发者

Binding Services Quick Question

开发者 https://www.devze.com 2023-03-06 11:49 出处:网络
SO I am trying to bind a service with my application a开发者_如何学Gond I was wondering if its possible to bind that to every single activity (one service to 10 activities).

SO I am trying to bind a service with my application a开发者_如何学Gond I was wondering if its possible to bind that to every single activity (one service to 10 activities).

Thanks, Arber


Yes, you should in fact be using the same code in each Activity:

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);
}
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号