-
Notifications
You must be signed in to change notification settings - Fork 319
Android navigation view ANR #2997
Copy link
Copy link
Closed
Description
I am using mapbox navigation view in android. when my screen is open for some more minutes then it causes this ANR. I can only use navigation for max 1-2 mins then this appears. Also i am using fragment to load navigation with bottom tabs.
Library i have used : 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.42.6'
ANR in com.flashmarket.delivery
PID: 15025
Reason: Broadcast of Intent { act=com.mapbox.android.telemetry.location.locationupdatespendingintent.action.LOCATION_UPDATED flg=0x10 hwFlg=0x300 (has extras) }
Load: 46.51 / 45.27 / 44.97
CPU usage from 137983ms to 0ms ago (2020-05-19 17:10:53.170 to 2020-05-19 17:13:11.153):
13% 656/surfaceflinger: 7% user + 6% kernel / faults: 2061 minor
9.5% 1320/system_server: 6.4% user + 3% kernel / faults: 37300 minor 8 major
5.3% 622/vendor.huawei.hardware.hwdisplay.displayengine@1.2-service: 2.8% user + 2.5% kernel
4.9% 605/android.hardware.graphics.composer@2.2-service: 2.3% user + 2.6% kernel / faults: 113 minor
4.7% 3472/com.google.android.googlequicksearchbox:search: 3% user + 1.7% kernel / faults: 23587 minor 28 major
3.5% 2073/com.huawei.android.launcher: 2.3% user + 1.2% kernel / faults: 25493 minor
3.2% 843/hwpged: 0% user + 3.2% kernel / faults: 91 minor
2.7% 13056/kworker/u16:2: 0% user + 2.7% kernel / faults: 10 minor
2.4% 13063/kworker/u16:15: 0% user + 2.4% kernel / faults: 1 minor
2% 10020/com.android.vending: 1.6% user + 0.3% kernel / faults: 26183 minor 30 major
1.9% 869/hiview: 1.5% user + 0.4% kernel / faults: 2601 minor 179 major
1.9% 1779/com.android.systemui: 1.2% user + 0.7% kernel / faults: 14103 minor 33 major
1.5% 13064/kworker/u16:16: 0% user + 1.5% kernel / faults: 86 minor
1.4% 14800/kworker/u16:1: 0% user + 1.4% kernel / faults: 233 minor
1.2% 21493/adbd: 0.3% user + 0.9% kernel / faults: 1191 minor
1.1% 3112/com.google.android.gms: 0.8% user + 0.2% kernel / faults: 9567 minor 33 major
0.8% 2029/com.huawei.iaware: 0.5% user + 0.3% kernel / faults: 3531 minor
0.8% 9/rcu_preempt: 0% user + 0.8% kernel
0.7% 13775/kworker/u16:0: 0% user + 0.7% kernel
0.7% 2283/com.google.android.gms.persistent: 0.5% user + 0.2% kernel / faults: 3307 minor 15 major
0.7% 454/logd: 0.2% user + 0.4% kernel / faults: 55 minor
0.6% 455/servicemanager: 0.2% user + 0.4% kernel
0.4% 1039/hisi_frw/0: 0% user + 0.4% kernel
0.4% 11402/kworker/u17:4: 0% user + 0.4% kernel
0.4% 662/powerlogd: 0.3% user + 0.1% kernel / faults: 7 minor
0.1% 2951/sugov:4: 0% user + 0.1% kernel
0.3% 648/audioserver: 0.2% user + 0.1% kernel / faults: 64 minor
0.3% 13256/kworker/u17:0: 0% user + 0.3% kernel
0.3% 15880/kworker/1:0H: 0% user + 0.3% kernel
0.3% 17288/zygote64: 0.1% user + 0.1% kernel / faults: 854 minor 18 major
0.2% 652/lmkd: 0% user + 0.2% kernel / faults: 3 minor
0.2% 2949/sugov:0: 0% user + 0.2% kernel
0.2% 805/dubaid: 0.1% user + 0.1% kernel / faults: 440 minor
0.2% 824/thermal-daemon: 0% user + 0.2% kernel
0% 799/ITouchservice: 0% user + 0% kernel / faults: 20 minor 2 major
0.2% 1048/hisi_hcc: 0% user + 0.2% kernel
0.2% 2055/com.android.phone: 0.1% user + 0% kernel / faults: 330 minor
0.2% 262/mmc-cmdqd/0: 0% user + 0.2% kernel
0% 819/mediaserver: 0% user + 0% kernel / faults: 201 minor
0% 9542/com.google.android.tts: 0% user + 0% kernel / faults: 5466 minor 41 major
0% 13057/kworker/u16:5: 0% user + 0% kernel
0.1% 584/zygote64: 0% user + 0.1% kernel / faults: 1872 minor
0.1% 821/statsd: 0% user + 0% kernel / faults: 6 minor
0% 2341/com.google.android.ext.services: 0% user + 0% kernel / faults: 1019 minor
0.1% 1049/hisi_rxdata: 0% user + 0.1% kernel
0.1% 851/vendor.huawei.hardware.sensors@1.0-service: 0% user + 0% kernel
0.1% 1933/com.huawei.hiview: 0% user + 0% kernel / faults: 115 minor
0.1% 583/netd: 0% user + 0% kernel / faults: 486 minor
0.1% 1034/oal_gpio_rx_dat: 0% user + 0.1% kernel
0.1% 2112/com.huawei.systemmanager:service: 0.1% user + 0% kernel / faults: 798 minor
0.1% 612/vendor.huawei.hardware.audio@5.0-service: 0% user + 0% kernel / faults: 65 minor
0% 811/installd: 0% user + 0% kernel / faults: 145 minor
0.1% 3388/transport: 0% user + 0% kernel / faults: 3 minor
0.1% 18/ksoftirqd/1: 0% user + 0.1% kernel
0% 852/media.swcodec: 0% user + 0% kernel / faults: 99 minor
0.1% 647/ashmemd: 0% user + 0% kernel
0.1% 803/displayengine
Here is my fragment code ::
import android.annotation.SuppressLint
import android.content.Context
import android.location.Address
import android.location.Geocoder
import android.location.Location
import android.os.Bundle
import android.preference.PreferenceManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import androidx.appcompat.app.AppCompatDelegate
import androidx.fragment.app.Fragment
import com.fm.R
import com.fm.base.BaseFragment
import com.fm.model.DeliveryListData
import com.fm.model.LatLongData
import com.fm.model.Message
import com.fm.model.RouteData
import com.fm.utils.Log
import com.mapbox.api.directions.v5.models.DirectionsResponse
import com.mapbox.api.directions.v5.models.DirectionsRoute
import com.mapbox.geojson.Point
import com.mapbox.mapboxsdk.Mapbox
import com.mapbox.services.android.navigation.ui.v5.NavigationViewOptions
import com.mapbox.services.android.navigation.ui.v5.OnNavigationReadyCallback
import com.mapbox.services.android.navigation.ui.v5.listeners.NavigationListener
import com.mapbox.services.android.navigation.v5.navigation.NavigationRoute
import com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress
import kotlinx.android.synthetic.main.fragment_navigation.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.util.*
import kotlin.collections.ArrayList
class NavigationFragment : BaseFragment(), OnNavigationReadyCallback, NavigationListener,
ProgressChangeListener {
private var directionsRoute: DirectionsRoute? = null
private var ORIGIN_LONGITUDE: Double = 0.0
private var ORIGIN_LATITUDE: Double = 0.0
private var DESTINATION_LONGITUDE: Double = 0.0
private var DESTINATION_LATITUDE: Double = 0.0
private var routeInfo: List<RouteData.RouteInfo.Route?> =
ArrayList()
private var total_count: String = ""
private var collected_count: String = ""
private var selectedItems: ArrayList<DeliveryListData.Data?> =
ArrayList()
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_navigation, container, false)
return view
}
@SuppressLint("ResourceType")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
navigationView?.onCreate(savedInstanceState)
navigationView?.initialize(this)
}
override fun onStart() {
try {
EventBus.getDefault().register(this)
super.onStart()
navigationView?.onStart()
} catch (e: Exception) {
}
}
override fun onResume() {
try {
super.onResume()
navigationView?.onResume()
} catch (e: Exception) {
}
}
override fun onSaveInstanceState(outState: Bundle) {
try {
navigationView?.onSaveInstanceState(outState)
super.onSaveInstanceState(outState)
} catch (e: Exception) {
}
}
override fun onPause() {
try {
super.onPause()
navigationView?.onPause()
} catch (e: Exception) {
}
}
override fun onStop() {
try {
EventBus.getDefault().unregister(this)
super.onStop()
navigationView?.onStop()
stopNavigation()
} catch (e: Exception) {
}
}
override fun onLowMemory() {
try {
super.onLowMemory()
navigationView?.onLowMemory()
} catch (e: Exception) {
}
}
override fun onNavigationReady(isRunning: Boolean) {
val origin = Point.fromLngLat(ORIGIN_LONGITUDE, ORIGIN_LATITUDE)
val destination = Point.fromLngLat(DESTINATION_LONGITUDE, DESTINATION_LATITUDE)
showProgressDialog()
fetchRoute(origin, destination)
}
override fun onCancelNavigation() {
try {
navigationView?.stopNavigation()
stopNavigation()
} catch (e: Exception) {
}
}
override fun onNavigationFinished() {
}
override fun onNavigationRunning() {
}
override fun onProgressChange(location: Location, routeProgress: RouteProgress) {
// Update InstructionView data from RouteProgress
/*val isInTunnel = routeProgress.inTunnel()
val wasInTunnel = wasInTunnel()
if (isInTunnel) {
if (!wasInTunnel) {
updateWasInTunnel(true)
updateCurrentNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}
} else {
if (wasInTunnel) {
updateWasInTunnel(false)
updateCurrentNightMode(AppCompatDelegate.MODE_NIGHT_AUTO)
}
}*/
Log.e("progress", "" + routeProgress.distanceRemaining())
if (routeProgress.distanceRemaining() <= 50.0) {
val fragment: Fragment?
fragment = if (selectedItems.size == 1) {
EventBus.getDefault()
.postSticky(Message("1", selectedItems, "collection", "", "single"))
CollectionRouteFragment()
} else {
EventBus.getDefault()
.postSticky(Message("1", selectedItems, "collection", "", "bulk"))
CollectionRouteFragment()
}
val transaction = activity?.supportFragmentManager?.beginTransaction()
transaction?.replace(R.id.container, fragment)
transaction?.commit()
try {
navigationView?.onStop()
stopNavigation()
} catch (e: Exception) {
}
}
}
private fun fetchRoute(origin: Point, destination: Point) {
NavigationRoute.builder(context)
.accessToken(Mapbox.getAccessToken()!!)
.origin(origin)
.destination(destination)
.build()
.getRoute(object : Callback<DirectionsResponse> {
override fun onResponse(
call: Call<DirectionsResponse>,
response: Response<DirectionsResponse>
) {
directionsRoute = response.body()!!.routes()[0]
try {
startNavigation()
} catch (e: Exception) {
}
}
override fun onFailure(call: Call<DirectionsResponse>, t: Throwable) {}
})
}
private fun startNavigation() {
if (directionsRoute == null) {
return
}
val options = NavigationViewOptions.builder()
.directionsRoute(directionsRoute)
.shouldSimulateRoute(true)
.navigationListener(this)
.progressChangeListener(this)
.build()
try {
navigationView?.startNavigation(options)
navigationView?.findViewById<View>(R.id.summaryBottomSheet)?.visibility = View.GONE
navigationView?.findViewById<View>(R.id.feedbackFab)?.visibility = View.GONE
navigationView?.findViewById<View>(R.id.soundFab)?.visibility = View.GONE
val param =
navigationView!!.findViewById<View>(R.id.instructionLayout).layoutParams as ViewGroup.MarginLayoutParams
param.setMargins(40, 100, 40, 0)
navigationView!!.findViewById<View>(R.id.instructionLayout).layoutParams = param
val vto: ViewTreeObserver =
navigationView?.findViewById<View>(R.id.instructionLayout)!!.getViewTreeObserver()
vto.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
navigationView?.findViewById<View>(R.id.instructionLayout)!!
.getViewTreeObserver()
.removeOnGlobalLayoutListener(this)
val bottom: Int =
navigationView?.findViewById<View>(R.id.instructionLayout)!!.bottom
val height: Int =
navigationView?.findViewById<View>(R.id.instructionLayout)!!
.measuredHeight
Log.e("height", "" + height)
Log.e(
"height-bottom",
"" + navigationView?.findViewById<View>(R.id.instructionLayout)!!.bottom
)
val param = llMain.layoutParams as ViewGroup.MarginLayoutParams
param.setMargins(40, height + 130, 40, 0)
llMain.layoutParams = param
llMain.visibility = View.VISIBLE
dismissProgressDialog()
}
})
} catch (e: Exception) {
}
}
private fun wasInTunnel(): Boolean {
val context: Context? = getContext()
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
return preferences.getBoolean("was_in_tunnel", false)
}
private fun updateWasInTunnel(wasInTunnel: Boolean) {
val context: Context? = getContext()
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
val editor = preferences.edit()
editor.putBoolean("was_in_tunnel", wasInTunnel)
editor.apply()
}
private fun updateCurrentNightMode(nightMode: Int) {
AppCompatDelegate.setDefaultNightMode(nightMode)
activity?.recreate()
}
@Subscribe(sticky = true)
fun onMessage(event: LatLongData) {
ORIGIN_LONGITUDE = event.start_lng
ORIGIN_LATITUDE = event.start_lat
DESTINATION_LATITUDE = event.end_lat
DESTINATION_LONGITUDE = event.end_lng
routeInfo = event.routeInfo
total_count = event.total_count
collected_count = event.collected_count
tvDeliveries?.text = collected_count + "/" + total_count
selectedItems = event.selectedItems!!
tvStartSubrub.text = generateAddress(ORIGIN_LATITUDE, ORIGIN_LONGITUDE)
EventBus.getDefault().removeStickyEvent(event)
}
override fun onDestroy() {
super.onDestroy()
try {
if (navigationView != null) {
navigationView?.onStop()
stopNavigation()
}
} catch (e: Exception) {
}
}
private fun stopNavigation() {
// hide navigation view
navigationView.visibility = View.GONE
try {
navigationView.stopNavigation()
} catch (e: Exception) {
}
}
fun generateAddress(latitude: Double, longitude: Double): String {
val addresses: List<Address>
val geocoder = Geocoder(context, Locale.getDefault())
addresses = geocoder.getFromLocation(
latitude,
longitude,
1
) // Here 1 represent max location result to returned, by documents it recommended 1 to 5
val address: String = addresses[0]
.getAddressLine(0) // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
val city: String = addresses[0].locality
val state: String = addresses[0].adminArea
val country: String = addresses[0].countryName
val postalCode: String = addresses[0].postalCode
val knownName: String = addresses[0].featureName // Only if available else return NULL
return "$address $city $postalCode $state $country"
}
}
My layout file ::
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tvTitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_21"
android:layout_marginTop="@dimen/margin_40"
android:fontFamily="@font/roboto_bold"
android:text="@string/tab_accepted"
android:textColor="@color/black"
android:textSize="@dimen/font_24" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mapbox.services.android.navigation.ui.v5.NavigationView
android:id="@+id/navigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/margin_10"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navigationDarkTheme="@style/NavigationViewDark"
app:navigationLightTheme="@style/CustomNavigationViewLight" />
<LinearLayout
android:id="@+id/llMain"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:id="@+id/line"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_2"
android:background="@color/lineGray" />
<LinearLayout
android:id="@+id/llBulkRoute"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:elevation="@dimen/margin_5"
android:orientation="horizontal"
android:padding="@dimen/margin_10"
android:paddingBottom="@dimen/margin_18">
<View
android:layout_width="@dimen/margin_17"
android:layout_height="@dimen/margin_23"
android:layout_marginRight="@dimen/margin_10"
android:background="@drawable/ic_map_green" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/tvStartSubrub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:fontFamily="@font/roboto_bold"
android:text="31 Symonds St"
android:textColor="@color/black"
android:textSize="@dimen/font_16" />
<TextView
android:id="@+id/tvStartPoint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:fontFamily="@font/roboto_regular"
android:text="31 Symonds St"
android:textColor="@color/black"
android:textSize="@dimen/font_12"
android:visibility="gone" />
</LinearLayout>
<TextView
android:id="@+id/tvDeliveries"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:drawableLeft="@drawable/ic_list"
android:drawablePadding="@dimen/margin_7"
android:fontFamily="@font/roboto_bold"
android:textColor="@color/black"
android:textSize="@dimen/font_16"
tools:text="2/10" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels