java - Android:WAITING对象出现

标签 java android object null exists

我想不出等待对象出现的正确方法。我正在编写一个相机应用程序。拍照后,我将 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/

相关文章:

javascript - 如何在javaScript中添加变量作为json键

java - Kafka 支持 java 10 还是 java 11?

java - 如何从 zipgroupfileset 中排除?

android - 使用滑动 TabLayout 以编程方式更改选项卡

android - Android上的OpenCV初始化问题

android - Kotlin 协程在主线程上的异常处理程序

c++ - 为什么指向对象的第二个指针未设置为 NULL 而是对象指针?

java - Java 中的 Eratosthenes 筛法 : A Puzzle and some optimization

java - 如何在 netbeans 中打开/转换旧的 jbuilder java GUI 文件

javascript - HTML Web 表单 vals 到我的 JavaScript 数据 Obj