添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

In my application I have created one customized dialog box ,which is showed in both webview and normal android application,and also I doing some background operation when the dialog box is showed, when ever I called the mydialog function it shows my customized dialog box and also it return some values,it is perfectly working when I use webview+javainterface but it doesn't work with ordinary applications, the flow is

first I will get my dialog, after I do some process(here the main thread will wait ,dialog need to show,) then I will return the string ,the problem is dialog doesn't show when I called this function instead of that the dialog will showed after my background process finished.

I call this my dialog box like:

String sample=mydialog();
public String mydialog() {
            String mystring = null;
                    try {
                        customizeddialog m_dialog = new customizeddialog(myactivity.this);
                        m_dialog.setCancelable(false);
                        m_dialog.show();
                    } catch (Exception e) {
                Have you seen if the code ever exits that while loop?  Could you put some Log.d("DIALOG", "code has reached point x"); statements in the code to see what's happening?  I would say using a while loop is not a great idea—you're better off using something like a Handler which you can send a message once the dialog is ready.
– Andrew Wyld
                Mar 6, 2013 at 13:48
                @AndrewWyld  ,i tried all method nothing wokrs so finallly i come to while looop but it wokrks fine  with webview, Browser.addJavascriptInterface(new myclass(this), 			"AndroidFunction");, and then i  call mydialog in javascript ,it shows my dialog and returns the value to javascript
– Mr.Cool
                Mar 6, 2013 at 13:55

When you enter the synchronized block in mydialog() you acquire this's lock. Inside this synchronized block, you run ShowDialog() on the UI thread, and try to acquire this's lock again when you enter the synchronized block in ShowDialog.

Since the lock has already been acquired, it will wait until it is released in mydialog(), which will never happen because ShowDialog never executes past synchronized(this). What you have is deadlock.

It could be that in your while(customizeddialog.Get value() == null) loop, customizeddialog.Getvalue() doesn't return null and the dialog wasn't shown yet. – Eliezer Mar 6, 2013 at 17:02 ya agree with you but i need to value from that dialog box so that reason i put while ,but i show the dialog in uithread ,and also i put that loop in main thread,this method working fine when i call from webview – Mr.Cool Mar 7, 2013 at 5:17 You have myactivity.this.runOnUiThread(ShowDialog) immediately followed by while (customizeddialog.Getvalue() == null). What if the second statement is run before ShowDialog() has had a chance to run? Will customizeddialog be null? If it is not, will Getvalue() return something other than null? And I'm still confused about customizeddialog. Is it a class or a variable? Because in mydialog() you call customizeddialog.Getvalue(). Is Getvalue() static? Much easier to see what's going on with clean code. Also try to post more of it so there's more of a context (no pun intended) – Eliezer Mar 7, 2013 at 12:37

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.