Android:在 Asynctask 上创建 MapView 不起作用
我正在尝试在另一个线程上创建 MapView,因为加载 Activity 需要很长时间。
class MapCreation extends AsyncTask<Integer, Void, MapView>
{
MapActivity context;
public MapCreation(MapActivity context)
{
this.context = context;
}
@Override
protected MapView doInBackground(Integer... params)
{
ListView someListView = new ListView(context); //Completely fine!
MapView someMapView = new MapView(context, OMITTED_KEY); //!!!!CRASH!!!!
return someMapView;
}
protected void onPostExecute(MapView someMapView)
{
//do something
}
}
程序在“ThreadPoolExecutor.class”处停止:
} finally {
processWorkerExit(w, completedAbruptly);
}
注意:我确实知道每个进程 1 个实例的 MapActivity/MapView 限制。在执行此 AsyncTask 之前我尚未创建 MapView 对象。
I'm trying to create a MapView on another thread since it takes too long to load an Activity.
class MapCreation extends AsyncTask<Integer, Void, MapView>
{
MapActivity context;
public MapCreation(MapActivity context)
{
this.context = context;
}
@Override
protected MapView doInBackground(Integer... params)
{
ListView someListView = new ListView(context); //Completely fine!
MapView someMapView = new MapView(context, OMITTED_KEY); //!!!!CRASH!!!!
return someMapView;
}
protected void onPostExecute(MapView someMapView)
{
//do something
}
}
The program stops at "ThreadPoolExecutor.class" at:
} finally {
processWorkerExit(w, completedAbruptly);
}
Note: I do know about the MapActivity/MapView limit of 1 instance per process. I haven't created a MapView object prior to executing this AsyncTask.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从 XML 文件扩充地图,然后将其推送到布局容器。
公共无效运行()
{
尝试{
和地图 xml:
I inflate the map from an XML file and than push it to a layout container.
public void run()
{
try {
and the map xml:
首先,我认为您至少需要获取地图的调试密钥,否则您只会得到一个空白屏幕
,然后如果您阅读有关构造函数的信息,
地图必须扩展 MapActivity。
First I think you need at least to get the debug key for the map otherwise you will just get a blank screen
then if you read info about constructor
The map has to extend the MapActivity.