我试图通过共享偏好保存我的意图的价值,但努力。我无法保存任何值。有人可以建议。
我需要从onActivityResult
启动的缩进中获取值我甚至可以接受CharSequence作为字符串。我需要保存意图值
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST
&& resultCode == Activity.RESULT_OK) {
// The user has selected a place. Extract the name and address.
Place place = PlacePicker.getPlace(data, this);
LatLng placeLatLng = place.getLatLng(); // gett lat lng from place
double placeLat = placeLatLng.latitude;
double placeLong = placeLatLng.longitude;
final CharSequence name = place.getName();
final CharSequence address = place.getAddress();
final LatLng location = place.getLatLng();
Marker destination = mMap.addMarker(new MarkerOptions().position(new LatLng(placeLat, placeLong)).title("This is your destination"));
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//Current Location
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location myLocation = locationManager.getLastKnownLocation(provider);
//Current Location LatLong
final double currentLat = myLocation.getLatitude();
final double currentLng = myLocation.getLongitude();
//Directions From Current Location To Destination
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?" + "saddr=" + currentLat + "," + currentLng + "&daddr=" + placeLat + "," + placeLong));
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
//historyDBHandler.addHistory(history);
startActivity(intent);
}
}
private String getInfo(){
SharedPreferences sharedPreferences = getSharedPreferences("Place Details", Context.MODE_PRIVATE);
String mapInfo = sharedPreferences.getString("map Info", "no data recorded");
return mapInfo;
}
private void saveValues(CharSequence name, CharSequence address){
Double text = Double.valueOf(new String().toString());
SharedPreferences sharedPreferences = getSharedPreferences("Place Details", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("map info", "help" );
editor.commit();
}
答案 0 :(得分:0)
您正在使用密钥"地图信息"但是要使用密钥"映射信息"。