我有类创建连接到谷歌播放服务,当连接建立时onConnectedToGooglePlayService()
被调用。当新的mySerivce
开始时,首先要建立连接到播放服务,您可以在代码中看到。Android服务asyncrounous:如何确保连接建立之前运行onStartCommand
的问题是,连接到发挥服务需要一些时间,我不能肯定的是,当onStartCommand
叫我不能得到意向信息建立连接。
所以我的问题是:处理这种情况的最佳方法是什么?连接建立后,我想创建一个全局变量和处理意图,但我不确定这是做到这一点的正确方法。
public class myService extends Service implements ConnectedToGooglePlayService {
GoogleApiClient mGoogleApiClient;
@Override
public void onCreate() {
super.onCreate();
new ConnectToGooglePlayService(this, this).connect();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onConnectedToGooglePlayService(GoogleApiClient mGoogleApiClient) {
this.mGoogleApiClient = mGoogleApiClient;
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
目前尚不清楚你想要达到的目标。在调用onConnectedToGooglePlayService之前,确保'onStartCommand'中的代码不会被执行? – Vasiliy
是的,这就是我想要实现的目标 – user2610533