我想不出等待对象出现的正确方法。我正在编写一个相机应用程序。拍照后,我将 GPS 数据写入 exif 标签中。在写入之前,我必须等待位置对象出现。我的快速而肮脏的修复是启动一个新线程并使用 while 循环来“等待”对象:
private static class MyRunnable implements Runnable {
private final String imagePath;
private final String thumbPath;
MyRunnable(final String anImagePath, String aThumbPath) {
this.imagePath = anImagePath;
this.thumbPath = aThumbPath;
}
public void run() {
while (mCurrentLocation == null) {
//do nothing
}
try {
writeExifTags(imagePath);
writeExifTags(thumbPath);
}
catch (NullPointerException e) {
Log.i(TAG, "NullPointerException");
}
}
}
这可行,但空的 while 循环看起来非常难看。我想到了该对象的某种处理程序,但想不出一种使用处理程序来检查 mCurrentLocation 是否存在的方法。有谁有智慧的闪光吗? :)(是的,try/catch block 现在已经过时了 ^^)
最佳答案
您可以尝试使用 AsyncTask 吗?
关于java - Android:WAITING对象出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4951551/