I want to pass some String arrays and size of that arrays in order to get location to show on a map activity.But the problem is I couldn't declare string arrays on the top of the onCreate method and it was declared in on create method since I used intent to pass variable.Therefore I couldn't use those arrays in the onMapReady method.
My codes are as follows,In my first activity
Intent SSMapIntent =new
Intent(SchoolSelectorMainActivity.this,MapsActivity.class);
SSMapIntent.putExtra("maxDistance",Str_maxdistance);
SSMapIntent.putExtra("source", 1);
SSMapIntent.putExtra("listCount",listCount);
if(listCount!=0){
SSMapIntent.putExtra("nameList",nameListIntent);
SSMapIntent.putExtra("typeList", typeListIntent);
SSMapIntent.putExtra("distanceList",distanceListIntent);
SSMapIntent.putExtra("latitude",latListIntent);
SSMapIntent.putExtra("longitude",lngListIntent);
}
startActivity(SSMapIntent);
My map activity
public class MapsActivity extends FragmentActivity implements
OnMapReadyCallback {
private GoogleMap mMap;
int source,tempInt,listCount;
String message1="",message2="",message3="",message4="";
String [][] selectedListTxt = new String[listCount][3];//for get name,lat,lng
double maxDistance;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
source=bundle.getInt("source");
maxDistance=bundle.getDouble("maxDistance");
if (source==1){
listCount=bundle.getInt("listCount");
}
if (listCount!=0) {
String[] nameListMap = bundle.getStringArray("nameList");
String[] typeListMap = bundle.getStringArray("typeList");
String[] distanceListMap= bundle.getStringArray("distanceList");
double [] latListMap=bundle.getDoubleArray("latitude");
double [] lngListMap=bundle.getDoubleArray("longitude");
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
//Here i can't use nameListMap,latListMap,lngListMap
}
}