编辑: glay 2014-02-25

// Always call the superclass method first // The activity is either being restarted or started for the first time // so this is where we should make sure that GPS is enabled LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

if (!gpsEnabled) { // Create a dialog here that requests the user to enable GPS, and use an intent // with the android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS action // to take the user to the Settings screen to enable GPS when they click "OK" } } @Override protected void onRestart() { super.onRestart();

// Always call the superclass method first // Activity being restarted from stopped state } 当系统销毁 activity 时会调用 onDestroy()方法, 因为在此之前的 onStop()方法中应该已 经释放了大部分资源,所以 onDestroy()方法中几乎无事可做.该方法是清空可能导致内 存泄露的所有资源的最后机会, 必须保证多余的线程已被注销、 其他长时间运行的操作如方 法跟踪也已经停止. 上一节 下一节

下载(注:源文件不在本站服务器,都将跳转到源网站下载)
备用下载
发帖评论
相关话题
发布一个新话题