尝试获取我已经拥有的Google地图的快照。我有以下代码:
public class CaptureMapScreen extends AsyncTask<Void, Void, String> {
@Override
protected void onPreExecute()
{
Log.d("pre","pre-execute");
dialog = ProgressDialog.show(WalkStarted.this, "Uploading",
"Please wait...");
}
@Override
protected String doInBackground(Void... params) {
GoogleMap.SnapshotReadyCallback callback = new GoogleMap.SnapshotReadyCallback() {
Bitmap bitmap;
@Override
public void onSnapshotReady(Bitmap snapshot) {
// TODO Auto-generated method stub
bitmap = snapshot;
try {
Log.d("storage", Environment.getExternalStorageDirectory().toString());
FileOutputStream out = new FileOutputStream(save_loc);
// above "/mnt ..... png" => is a storage path (where image will be stored) + name of image you can customize as per your Requirement
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
UploadImageClass uim = new UploadImageClass();
int response = 0;
try {
response = uim.execute(save_loc).get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
System.out.println("RES : " + response);
} catch (Exception e) {
e.printStackTrace();
}
}
};
mMap.snapshot(callback);
return null;
}
}
在日志中,我看到了
12-19 07:40:46.731 13516-13516/ly.leash.Leashly D/ID﹕ 2131361924
12-19 07:40:46.731 13516-13516/ly.leash.Leashly D/pre﹕ pre-execute
12-19 07:40:46.951 13516-13516/ly.leash.Leashly D/storage﹕ /storage/emulated/0
12-19 07:40:52.231 13516-13932/ly.leash.Leashly I/uploadFile﹕ HTTP Response is : OK: 200
12-19 07:40:52.231 13516-13516/ly.leash.Leashly I/System.out﹕ RES : 200
12-19 07:40:52.231 13516-13516/ly.leash.Leashly I/Choreographer﹕ Skipped 338 frames! The application may be doing too much work on its main thread.
服务器响应内容来自我的UploadImageClass(另一个AsyncTask)。所以无论出于何种原因,我似乎无法在此活动开始时提出ProgressDialog。它在最后显示并消失。我可以明显地猜到/看到用户界面已被锁定,但我不知道在哪里,因为这是所有背景资料。
偶尔这会按照我的预期运行,并且ProgressDialog会出现,但通常情况下它并没有按预期工作。
编辑:我添加了
@Override
protected void onPostExecute(String args)
{
Log.d("post","post-execute2");
}
这也会在显示ProgressDialog之前打印
EDIT2:
启动此事件的我的OnClick仅启动此事件。在上面启动的Asynctask之后没有其他调用正在进行。我想也许谷歌地图Api搞砸了吗?也许onLocationChanged()调用或其他什么?
答案 0 :(得分:0)
你在哪里调用CaptureMapScreen AsyncTask?您可以在执行asyncTask之前显示对话框,而不是在onPreExecute()方法中。
例如:
dialog = ProgressDialog.show(WalkStarted.this, "Uploading",
"Please wait...");
CaptureMapScreen captureMapScreenTask = new GetBlogPostsTask();
captureMapScreenTask.execute();