如何使用wait()和notify()?

问题描述

我正在实施一个 dialog。但是我想在 dialog 关闭之前等待返回 variable。为此,我尝试实现 wait()notify() 方法,但我无法正常工作。 (它本质上不等待)。 返回部分:

lt = null;
            Log.d("nota_thing","Cant find any location");
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Log.d("nota_thing","Running");
                    MapsDialog dialog = new MapsDialog();
                    dialog.show(getSupportFragmentManager(),"maps_dialog");
                    Log.d("nota_thing","Runningv2");
                    synchronized (lock) {
                        while (lt!= null) {
                            try {
                                lock.wait();
                            } catch (InterruptedException e) {
                                e.printstacktrace();
                            }
                        }

                    }
                }
            });

            Log.d("nota_thing","Second try" + lt.toString());
            return lt;

对话监听器:

synchronized (lock) {
            lt = latLng;
            Log.d("nota_thing","notify");
            lock.notify();
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)