简体   繁体   English

MapFragment-应用程序可能在其主线程上做过多的工作

[英]MapFragment - The application may be doing too much work on its main thread

I was having the following error 我遇到以下错误

Skipped 40 frames!  The application may be doing too much work on its main thread.

Researched about it... Made sure everything started in new threads as much as possible with Runnables. 已对此进行了研究...确保Runnables尽可能使一切开始于新线程中。 But kept getting the error. 但不断得到错误。 I almostly commented all my code and still got it when I started a new activity. 我几乎注释了我所有的代码,但在开始一项新活动时仍然得到了它。 Then I commented this mapfragment from my first activity and there error was gone. 然后我在第一次活动中对此mapfragment进行了评论,然后错误消失了。 So the error is caused by following piece of code: 因此,错误是由以下代码引起的:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:name="com.google.android.gms.maps.MapFragment"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    />

I got this from Google Maps API for Android docs... Kind of weird it's not optimised. 我是从适用于Android文档的Google Maps API上获得的...有点奇怪,没有进行优化。 How can I make sure the error disappears? 如何确定错误消失了? Can I delay the load of the mapFragment? 我可以延迟mapFragment的加载吗?

Once I opened the Activity once... and reopen it again the warning is gone because it's in the memory already.. but I'd like to have the best optimised app possible. 一旦我打开活动一次,然后再次将其重新打开,警告就消失了,因为它已经在内存中了..但我想拥有最好的最佳应用程序。

To avoid confusion It's the setContentView that is causing delay because the mapFragment is loaded in this function. 为了避免混淆 ,是setContentView引起延迟,因为此函数中加载了mapFragment。 The delay causes a warning to be thrown. 延迟会引发警告。 My question: how can I speed up the setContentView, so the mapFragment is pre-loaded or loads after the activity is opened. 我的问题是:如何加快setContentView的速度,以便在活动打开后预加载mapFragment或加载它。

setContentView() slow with map fragment setContentView()与地图片段比较慢

This contains the answer. 这包含答案。 Was deeply down hidden in Google, but found it! 被Google深深隐藏,却找到了!

Try like this 这样尝试

getMapAsync(OnMapReadyCallback callback) you can set up listener for when GoogleMap is ready getMapAsync(OnMapReadyCallback回调),您可以在GoogleMap准备就绪时设置侦听器

public class MainActivity extends FragmentActivity
    implements OnMapReadyCallback {  
...  
}  
@Override  
public void onMapReady(GoogleMap map) {
    map.addMarker(new MarkerOptions()
        .position(new LatLng(0, 0))
        .title("Marker"));
} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 该应用程序可能在其主线程上做了大量工作(Android) - The application may be doing too much work on its main thread, (Android) Android-该应用程序可能在其主线程上做了大量工作 - Android - The application may be doing too much work on its main thread 此应用程序可能在其主线程中做过多的工作 - This application may be doing too much work in its main thread 跳过32帧! 该应用程序可能会在其主线程上执行过多的工作,然后执行FATAL EXCEPTION:main - Skipped 32 frames! The application may be doing too much work on its main thread and then FATAL EXCEPTION: main 单击按钮创建BaiDuMap时,请解决此错误:应用程序可能在其主线程上执行了太多工作 - When click a button to create a BaiDuMap,thread this error:The application may be doing too much work on its main thread 跳过104帧! 该应用程序可能在其主线程上做过多的工作 - Skipped 104 frames! The application may be doing too much work on its main thread ImageButton问题。 跳了35帧! 该应用程序可能在其主线程上做过多的工作 - ImageButton issues. Skipped 35 frames! The application may be doing too much work on its main thread 如何避免应用程序可能在其主线程上做过多的工作 - How to avoid The application may be doing too much work on its main thread 跳过49帧!应用程序可能在其主线程上做了太多工作 - Skipped 49 frames! The application may be doing too much work on its main thread android 跳过44帧! 应用程序可能在其主线程上做了太多工作 - android Skipped 44 frames! The application may be doing too much work on its main thread
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM