[android] - clear callbacks as part of OnDestroy not as part of OnDestroyView

This commit is contained in:
tobrun
2019-03-05 10:33:03 +01:00
committed by Tobrun
parent 383fde6804
commit be75dc9a48
8 changed files with 94 additions and 7 deletions

View File

@@ -198,6 +198,14 @@ public final class MapFragment extends Fragment implements OnMapReadyCallback {
public void onDestroyView() {
super.onDestroyView();
map.onDestroy();
}
/**
* Called when the fragment is destroyed.
*/
@Override
public void onDestroy() {
super.onDestroy();
mapReadyCallbackList.clear();
}

View File

@@ -187,12 +187,20 @@ public class SupportMapFragment extends Fragment implements OnMapReadyCallback {
}
/**
* Called when the fragment is view hiearchy is being destroyed.
* Called when the fragment is view hierarchy is being destroyed.
*/
@Override
public void onDestroyView() {
super.onDestroyView();
map.onDestroy();
}
/**
* Called when the fragment is destroyed.
*/
@Override
public void onDestroy() {
super.onDestroy();
mapReadyCallbackList.clear();
}

View File

@@ -162,7 +162,7 @@
<activity
android:name=".activity.fragment.SupportMapFragmentActivity"
android:description="@string/description_map_fragment_support"
android:label="@string/activity_map_fragment_suport">
android:label="@string/activity_map_fragment_support">
<meta-data
android:name="@string/category"
android:value="@string/category_fragment" />
@@ -170,6 +170,17 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
</activity>
<activity
android:name=".activity.fragment.FragmentBackStackActivity"
android:description="@string/description_map_fragment_backstack"
android:label="@string/activity_map_fragment_backstack">
<meta-data
android:name="@string/category"
android:value="@string/category_fragment" />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
</activity>
<activity
android:name=".activity.fragment.MultiMapActivity"
android:description="@string/description_multimap"
@@ -895,9 +906,6 @@
android:value=".activity.FeatureOverviewActivity" />
</activity>
<!-- For Instrumentation tests -->
<activity
android:name=".activity.style.RuntimeStyleTestActivity"
android:screenOrientation="portrait" />
<activity
android:name=".activity.style.RuntimeStyleTimingTestActivity"
android:screenOrientation="portrait" />

View File

@@ -0,0 +1,45 @@
package com.mapbox.mapboxsdk.testapp.activity.fragment
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.maps.SupportMapFragment
import com.mapbox.mapboxsdk.testapp.R
import kotlinx.android.synthetic.main.activity_backstack_fragment.*
/**
* Test activity showcasing using the MapFragment API as part of a backstacked fragment.
*/
class FragmentBackStackActivity : AppCompatActivity() {
private lateinit var mapFragment: SupportMapFragment
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_backstack_fragment)
mapFragment = SupportMapFragment.newInstance()
mapFragment.getMapAsync { initMap(it) }
supportFragmentManager.beginTransaction().apply {
add(R.id.container, mapFragment)
}.commit()
button.setOnClickListener { handleClick(it) }
}
private fun initMap(mapboxMap: MapboxMap) {
mapboxMap.setStyle(Style.SATELLITE) {
mapboxMap.setPadding(300, 300, 300, 300)
}
}
private fun handleClick(button: View) {
supportFragmentManager.beginTransaction().apply {
replace(R.id.container, NestedViewPagerActivity.ItemAdapter.EmptyFragment())
addToBackStack("map_empty_fragment")
}.commit()
}
}

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button android:layout_width="match_parent"
android:layout_height="58dp"
android:id="@+id/button"
android:text="Replace with empty fragment"/>
</FrameLayout>

View File

@@ -5,6 +5,7 @@
<string name="description_cameraposition">CameraPosition capabilities</string>
<string name="description_map_fragment">Showcase MapFragment</string>
<string name="description_map_fragment_support">Showcase SupportMapFragment</string>
<string name="description_map_fragment_backstack">Showcase using a Map Fragment with a fragment backstack</string>
<string name="description_multimap">Activity with multiple maps on screen</string>
<string name="description_press_for_marker">Add marker to map on long press</string>
<string name="description_camera_zoom">Different types of zoom methods</string>

View File

@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="activity_map_fragment_suport">Support Map Fragment</string>
<string name="activity_map_fragment_support">Support Map Fragment</string>
<string name="activity_map_fragment">Map Fragment</string>
<string name="activity_map_fragment_backstack">Backstack Map Fragment</string>
<string name="activity_multimap">Multiple Maps on Screen</string>
<string name="activity_add_bulk_markers">Add Markers In Bulk</string>
<string name="activity_animated_symbollayer">Animated SymbolLayer</string>

View File

@@ -45,5 +45,6 @@
"RuntimeStyleActivity",
"GridSourceActivity",
"AnimatedImageSourceActivity",
"EspressoTestActivity"
"EspressoTestActivity",
"FragmentBackStackActivity"
]