Issue
I have a simple activity with just a MapView element. The map is loaded fine but as soon as I zoom in / out the app just crashes without giving me any sort of log (I also tried without the package filter, but anything usefull appeared). The only thing I can suspect is a memory problem, but I don't know how to check and eventually fix it.
Activity:
public class PointsOfInterest extends AppCompatActivity implements OnMapReadyCallback {
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_map);
/* MapView */
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
@Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onMapReady(GoogleMap map) {
map.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
@Override
protected void onPause() {
mapView.onPause();
super.onPause();
}
@Override
protected void onDestroy() {
mapView.onDestroy();
super.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}
Layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="230dp" />
</LinearLayout>
UPDATE: same problem with fragment:
Activity:
public class PointsOfInterest extends AppCompatActivity implements OnMapReadyCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_map);
SupportMapFragment mMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mMapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
}
}
Layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="230dp" />
</LinearLayout>
By the way, if I try with "match_parent" instead of 230dp, the app restarts as soon as I move the map or zoom in / out (in other words, when I have to load new map data). The smaller the map is, the longer I can use it. This makes me think even more to a memory problem (anyway, RAM usage is just 40MB with peaks of 50MB when loading map, with an immediate GC which takes down again to 40MB)
Solution
Apparently you are trying to use the map in lite mode. The document says that, in that mode, user is not allowed to pan or zoom.
If you really need the pan/zoom functionality, do this instead:
1) Add this fragment to your activity layout xml:
...
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />
...
2) Initialize the map like this on your activity onCreate
:
mMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mMapFragment.getMapAsync(this);
Answered By - muratgu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.