刷新地图/活动使用提示打开GPS后

时间:2017-02-02 08:47:54

标签: android google-maps gps

刷新地图/活动使用提示打开GPS后。 我已经这样做但它没有刷新活动。 这是我的代码:

public void showSettingsAlert(){

    AlertDialog.Builder alertDialog = new AlertDialog.Builder(HomeActivity.this);

    // Setting Dialog Title
    alertDialog.setTitle("GPS is settings");

    // Setting Dialog Message
    alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");

    // Setting Icon to Dialog
    alertDialog.setIcon(R.mipmap.ic_launcher);

    // On pressing Settings button
    alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,int which) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            HomeActivity.this.startActivity(intent);
            loadData();
        }
    });

    // on pressing cancel button
    alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    // Showing Alert Message
    alertDialog.show();
}

如何刷新活动?

checkGPS();

private void checkGPS(){         if(!SmartLocation.with(this).location()。state()。locationServicesEnabled()||!SmartLocation.with(this).location()。state()。isAnyProviderAvailable()){             maketoast("位置服务未启用!!");             showSettingsAlert();         }     }

2 个答案:

答案 0 :(得分:0)

@Override
protected void onResume() {
    super.onResume();

    if(GPS on){
         activity refresh..
    }else{
         showSettingsAlert();
    }
}

答案 1 :(得分:0)

在打开GPS后刷新OnResume()中的活动,并在SharedPreference的帮助下完成,以避免无限循环问题。