0
我对Android很新,所以任何帮助,将不胜感激。检索当前位置
我只是在开发者网站上关注一些教程,但在检索当前位置时遇到了一些代码问题。我花了几个小时寻找答案,但没有运气。这里是一个片段:
public class MainActivity extends FragmentActivity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
/*
* Create a new location client, using the enclosing class to
* handle callbacks.
*/
mLocationClient = new LocationClient(this, this, this);
...
}
...
/*
* Called when the Activity becomes visible.
*/
@Override
protected void onStart() {
super.onStart();
// Connect the client.
mLocationClient.connect();
}
...
/*
* Called when the Activity is no longer visible.
*/
@Override
protected void onStop() {
// Disconnecting the client invalidates it.
mLocationClient.disconnect();
super.onStop();
}
...
}
我遇到的问题是,mLocationClient不能在在onStart()和的onStop()方法来解决。当mLocationClient在oncreate()中安装时是否可以在onStart()和onStop()中使用?
不,它不会在onStop()和onStart()中可用。在onCreate()之外初始化它以获得这种可见性! –