I've added onNewIntent(intent) to my activity, so when it's called it should zoom on a specific location on my map and then call invalidateOptionsMenu(), so that onCreateOptionsMenu() can be called and update the spinner in my action bar with the name of the new location. The problem is after i add invalidateOptionsMenu() to the onNewIntent(), animateCamera always shows the first location that i've added to the spinner. For example, i have three locations (London, Paris, Milano) and i add another (New York) and it should zoom to New York, but it zooms always to London. Here's my code.
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
final String name = intent.getStringExtra("name");
ArrayList<String> loc = helper.getLocation(name); //here i get the coordinates for the location from database
String lat = loc.get(0);
String lng = loc.get(1);
double lat1 = Double.parseDouble(lat);
double lng1 = Double.parseDouble(lng);
LatLng tochka = new LatLng(lat1, lng1);
CameraUpdate camera = CameraUpdateFactory.newLatLngZoom(tochka, 17);
map.animateCamera(camera);
map.addMarker(new MarkerOptions().position(tochka).title(name));
invalidateOptionsMenu();
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.spinner, menu);
MenuItem item = menu.findItem(R.id.spinner);
spinner = (Spinner) MenuItemCompat.getActionView(item);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.row, R.id.weekofday, Locations);
adapter.setDropDownViewResource(R.layout.row);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
return true;
}
Thanks.