From eef37c013b09f93d277c19cb05b80f4123060d23 Mon Sep 17 00:00:00 2001 From: tobrun Date: Tue, 5 Mar 2019 10:33:03 +0100 Subject: [PATCH] [android] - clear callbacks as part of OnDestroy not as part of OnDestroyView --- .../mapbox/mapboxsdk/maps/MapFragment.java | 8 ++++ .../mapboxsdk/maps/SupportMapFragment.java | 10 ++++- .../src/main/AndroidManifest.xml | 16 +++++-- .../fragment/FragmentBackStackActivity.kt | 45 +++++++++++++++++++ .../layout/activity_backstack_fragment.xml | 15 +++++++ .../src/main/res/values/descriptions.xml | 1 + .../src/main/res/values/titles.xml | 3 +- .../android/scripts/exclude-activity-gen.json | 3 +- 8 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/FragmentBackStackActivity.kt create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_backstack_fragment.xml diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java index 2ad4837bb79..8af9f2c6a86 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java @@ -198,6 +198,14 @@ public void onLowMemory() { public void onDestroyView() { super.onDestroyView(); map.onDestroy(); + } + + /** + * Called when the fragment is destroyed. + */ + @Override + public void onDestroy() { + super.onDestroy(); mapReadyCallbackList.clear(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java index e3155c417be..011a0bdaa28 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java @@ -187,12 +187,20 @@ public void onLowMemory() { } /** - * 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(); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 22ae7f98243..da2a0cdc195 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -162,7 +162,7 @@ + android:label="@string/activity_map_fragment_support"> @@ -170,6 +170,17 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".activity.FeatureOverviewActivity" /> + + + + - diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/FragmentBackStackActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/FragmentBackStackActivity.kt new file mode 100644 index 00000000000..be4d3d2f1b0 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/FragmentBackStackActivity.kt @@ -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() + } +} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_backstack_fragment.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_backstack_fragment.xml new file mode 100644 index 00000000000..b6b672cf73b --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_backstack_fragment.xml @@ -0,0 +1,15 @@ + + + + + +