Oh, and one more thing: the activity not getting displayed likely has something to do with the thread going into a wait state right after you call startActivity.

Since the call to queryUserSave comes from background thread (as I understand from your email), you could use runOnUIThread() with a runnable that in turn calls startActivity, just to make sure that the flow of starting the activity is not blocked.

-- Kostya

22.12.2010 20:58, Dianne Hackborn ?????:
startActivity() always runs the activity on the main thread.

How about just looking at your app in the debugging to see where the threads are stuck?

On Wed, Dec 22, 2010 at 7:11 AM, Schoel <[email protected] <mailto:[email protected]>> wrote:

    I have a function call from a large engine (which I can not change)
    which asks the user whether to save or not. Before this function call
    returns, I need an answer from the user whether to save.

    There is, as far as I know, no way to start an activity (or show a
    dialog) that synchronously returns an answer. Therefore I did like
    this (code is not complete but should be enough for understanding):

    int queryUserSave()
    {
      s_Semaphore.acquire();
      startActivity(QueryUserSaveActivity);
      s_Semaphore.acquire();
      s_Semaphore.release();
      return s_nQueryUserSaveResult;
    }

    void onQueryUserSaveResult(int aResult)
    {
      s_nQueryDialingLineResult = aResult;
      s_Semaphore.release();
    }


    The problem is, on the second acquire, the program halts (as intended)
    without spawning the QueryUserSaveActivity (not as intended). The idea
    was that the QueryUserSaveActivity would be spawned and the second
    acquire would block until onQueryUserSaveResult is called.
    I've checked the thread id of the thread in which queryUserSave is
    called and the thread id in which the QueryUserSaveActivity is started
    (if I don't use any semaphores) and they are not the same. I thus
    conclude that startActivity starts the activity in another thread (the
    UI thread) and therefore shouldn't care about the second acquire call.
    I also tried setting the startActivity in its own thread and start
    that thread with the same result as above.
    Do you have any ideas what I can do to solve this?

    Appriciate any help,
    Schoel

    --
    You received this message because you are subscribed to the Google
    Groups "Android Developers" group.
    To post to this group, send email to
    [email protected]
    <mailto:[email protected]>
    To unsubscribe from this group, send email to
    [email protected]
    <mailto:android-developers%[email protected]>
    For more options, visit this group at
    http://groups.google.com/group/android-developers?hl=en




--
Dianne Hackborn
Android framework engineer
[email protected] <mailto:[email protected]>

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to