I am creating very simple application and trying to learn android.
In this application i created one activity which contains Map and it also has option menu on the click of option menu item opens up another activity and closes current map here is the code.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent = new Intent();
if (item.getItemId() == R.id.LegalNotice) {
intent.setClass(Map.this, LegalNotices.class);
} else if (item.getItemId() == R.id.ChangeDistance) {
intent.setClass(Map.this, ChangeDefaultDistance.class);
}
startActivity(intent);
this.finish();
return true;
}
Now here ChangeDefaultDistance is activity which contains only list view. Now when particular item is selected from list view i am again starting the Map activity.Here is the code.
@Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
TextView tv;
tv = (TextView) view;
Map.distance = tv.getText().toString();
startActivity(new Intent(ChangeDefaultDistance.this, Map.class));
}
Now when again map starts it executes onCreate() method but previously in onCreate method i zoomed map to particular position and drawn marker now it is not zoomed and not drawing marker also.When i debugged the code i found that it is executing the code but nothing is happening.
Can anybody tell me why this is happening?
Here is the code of onCreate method also.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isGooglePlayAvailable()) {
criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
// Getting the service from context and giving to location_manager
location_manager = (LocationManager) getSystemService(LOCATION_SERVICE);
setContentView(R.layout.mapdemo);
placesTask = new PlacesTask();
getGoogleMap();
getUserLocation();
google_map.clear();
Toast.makeText(Map.this, "Hello Sexy!!!", Toast.LENGTH_LONG).show();
Toast.makeText(this, "Latitude:" + lat + " Longitude:" + lang,
Toast.LENGTH_LONG).show();
drawMarker();
// If Distance is not choosed default distance is given
if (distance.equals("")) {
distance = "1000";
}
sb = createUrl();
placesTask.execute(sb);
}
}
All the functions are working properly.
But it is not zooming again and drawing marker what can be the problem?