安装后启动应用程序只会在Samsung手机上导致崩溃。在其他手机上不会发生。错误是
java.lang.OutOfMemoryError:确保本地容量:
仅在安装后首次启动应用程序时发生崩溃。重新启动该应用程序时,它会运行,但会导致内存不断增加,而且永远不会清除。
这是代码:
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view= inflater.inflate(R.layout.fragment_place_search_results, container, false)
mapView = childFragmentManager.findFragmentById(R.id.placesearchresults_map) as SupportMapFragment
mapView.onCreate(savedInstanceState)
mapView.getMapAsync(this)
retainInstance = true
return view
}
override fun onResume() {
super.onResume()
mapView.onResume()
}
override fun onPause() {
super.onPause()
mapView.onPause()
}
override fun onStart() {
super.onStart()
mapView.onStart()
}
override fun onDestroy() {
super.onDestroy()
map?.clear()
mapView.onDestroy()
mapMarkerFactor.recycle()
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mapView.onSaveInstanceState(outState)
}
override fun onLowMemory() {
super.onLowMemory()
mapView.onLowMemory()
}
XML:
<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">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/placessearchresults_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/placessearchresults_map"
android:layout_width="match_parent"
android:layout_height="200dp"
android:visibility="visible"
android:clickable="true"
app:layout_collapseMode="parallax"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/placessearchresults_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"/>
<io.supercharge.shimmerlayout.ShimmerLayout
android:id="@+id/placessearchresults_loading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:shimmer_animation_duration="750"
app:shimmer_auto_start="true"
app:shimmer_color="@color/placeHolderShimmer"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
layout="@layout/placeholder_item_place_mini"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
layout="@layout/placeholder_item_place_mini"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
layout="@layout/placeholder_item_place_mini"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</io.supercharge.shimmerlayout.ShimmerLayout>
</android.support.design.widget.CoordinatorLayout>
这是Logcat
java.lang.OutOfMemoryError: EnsureLocalCapacity
at java.io.UnixFileSystem.list0(Native Method)
at java.io.UnixFileSystem.list(UnixFileSystem.java:303)
at java.io.File.list(File.java:1122)
at java.io.File.listFiles(File.java:1286)
at com.google.maps.api.android.lib6.gmm6.vector.ck.a(:com.google.android.gms.dynamite_mapsdynamite@13280048@13.2.80 (040400-211705629):82)
at com.google.maps.api.android.lib6.gmm6.api.h.a(:com.google.android.gms.dynamite_mapsdynamite@13280048@13.2.80 (040400-211705629):18)
at com.google.maps.api.android.lib6.gmm6.api.u.a(:com.google.android.gms.dynamite_mapsdynamite@13280048@13.2.80 (040400-211705629):80)
at com.google.android.gms.maps.internal.db.a(:com.google.android.gms.dynamite_mapsdynamite@13280048@13.2.80 (040400-211705629):33)
at com.google.maps.api.android.lib6.impl.bc.a(:com.google.android.gms.dynamite_mapsdynamite@13280048@13.2.80 (040400-211705629):170)
at com.google.maps.api.android.lib6.impl.bc.a(:com.google.android.gms.dynamite_mapsdynamite@13280048@13.2.80 (040400-211705629):124)
at com.google.maps.api.android.lib6.impl.co.a(:com.google.android.gms.dynamite_mapsdynamite@13280048@13.2.80 (040400-211705629):26)
at com.google.android.gms.maps.internal.t.a(:com.google.android.gms.dynamite_mapsdynamite@13280048@13.2.80 (040400-211705629):69)
at fh.onTransact(:com.google.android.gms.dynamite_mapsdynamite@13280048@13.2.80 (040400-211705629):10)
at android.os.Binder.transact(Binder.java:612)
at com.google.android.gms.internal.maps.zza.transactAndReadException(Unknown Source:7)
at com.google.android.gms.maps.internal.zzj.onCreateView(Unknown Source:14)
at com.google.android.gms.maps.SupportMapFragment$zza.onCreateView(Unknown Source:18)
at com.google.android.gms.dynamic.zzd.zza(Unknown Source:19)
at com.google.android.gms.dynamic.DeferredLifecycleHelper.zza(Unknown Source:6)
at com.google.android.gms.dynamic.DeferredLifecycleHelper.onCreateView(Unknown Source:20)
at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source:2)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2346)
at android.support.v4.app.FragmentManagerImpl.ensureInflatedFragmentView(FragmentManager.java:1664)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1399)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1659)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1905)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3715)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.myapplication.modules.place.search.results.PlaceSearchResultsFragment.onCreateView(SearchFragment.kt:88)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2346)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1428)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
2018-10-05 10:12:46.272 22520-22520/com.myapplication E/AndroidRuntime: at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2596)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2383)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:703)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
预先感谢