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()之外初始化它以獲得這種可見性! –