Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Clear callbacks as part of OnDestroy #14035

Merged
merged 1 commit into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,25 @@
<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" />
<meta-data
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"
Expand Down Expand Up @@ -884,9 +895,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" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
3 changes: 2 additions & 1 deletion platform/android/scripts/exclude-activity-gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@
"RuntimeStyleActivity",
"GridSourceActivity",
"AnimatedImageSourceActivity",
"EspressoTestActivity"
"EspressoTestActivity",
"FragmentBackStackActivity"
]