Hi all,
I'm working on a class (class A) containing a mapView and some other layers.
When calculating itinerary, I have the possibility to show the road instructions on a listView called on another class (class B).
From the listView, when pressing/selection an instruction, my app should go back to the map class (class A) to focus on that instruction coordinates.
The problem is, when coming back to the map class (class A), I got an error and my app crashes.
Here is the code of ListView (class B ) calling mapView class (class A).
final Intent i = new Intent(this, MapItineraire.class);
maListViewPerso.setOnItemClickListener(new OnItemClickListener() {
@Override
@SuppressWarnings("unchecked")
public void onItemClick(AdapterView<?> a, View v, int position,
long id) {
Bundle infoBundle = new Bundle();
infoBundle.putInt("position", position);
i.putExtras(infoBundle);
startActivity(i);
}
});
the mapView class contain MapView, some Layouts(as layers),
LocationListner...
I kept on resume empty, I got the crash
@Override
protected void onResume() {
super.onResume();
Bundle extras = getIntent().getExtras();
if (extras != null) {
position = extras.getInt("position");
}
}
PS: I can get the extra but the app crashes.
How can I reload the last State of mapView and the found itinerary when resuming ???
I would suggest to keep the MapComponent as singleton in the Application, so you do not recreate it with stop and resume of any Activity. We have recent better Android sample available in https://bitbucket.org/nutiteq/android-map-samples . It uses Application and shows many other general Maps lib features, and some specific tricks in Android: how to show route instructions, how to implement Search with Android API etc. There is also latest SDK, you need to use this to run the sample.
/JaakL