Re: [android-developers] Reliable way to programmatically open options menu on startup

2010-09-26 Thread Prakash Iyer
My bad. I interpreted the Runnable in your post to assume a new thread. That
Handler syntax always confuses me! Thanks.
On Sep 26, 2010 8:45 AM, "Mark Carter"  wrote:
> I think all these methods are called on the main thread, so this shouldn't
> be an issue.
>
> On 26 September 2010 14:23, Prakash Iyer  wrote:
>
>> would he also need to synchronize the threads? else in the thread that he
>> is displaying the options he might have checked the boolean and then just
>> before he calls his function to display the onStop could have got called
in
>> the other thread? possible?
>>
>>
>> On Sat, Sep 25, 2010 at 6:38 PM, Dianne Hackborn wrote:
>>
>>> isFinishing() is not what you want, that tells you if you have called
>>> finish(). The activity can be destroyed for other reasons, such as a
>>> configuration change. Just implement onStop() to set a flag to say not
to
>>> open the menu.
>>>
>>>
>>> On Sat, Sep 25, 2010 at 3:11 PM, Mark Carter wrote:
>>>
 Yeah, I was trying to remember why I posted it delayed - and I think
its
 because I was having the problem without the delay.

 I suppose, even if the post is not delayed, the user might still back
out
 before the openOptionsMenu gets to the front of the queue.

 Thanks - yeah, maybe use isFinishing() and possibly override it to set
a
 flag when super.isFinishing() returns. isFinished() would have been
nice!


 On 25 September 2010 23:48, TreKing  wrote:

> On Sat, Sep 25, 2010 at 3:11 AM, Mark Carter wrote:
>
>> Is there any way to avoid this?
>>
>
> Don't post it delayed? It's probably happening if a user clicks your
app
> to open it, then decides it was a mistake and tries to exit
immediately
> after, so the Activity is exiting by the time your Runnable runs.
>
>
>> Maybe a test to see whether the activity is still running? If so,
what
>> is the most reliable way to do that?
>>
>
> Maybe "isFinishing()"?
>
>
>
-
> TreKing  - Chicago
> transit tracking app for Android-powered devices
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to
> android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com

>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en


 --
 You received this message because you are subscribed to the Google
 Groups "Android Developers" group.
 To post to this group, send email to
android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com

>
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

>>>
>>>
>>>
>>> --
>>> Dianne Hackborn
>>> Android framework engineer
>>> hack...@android.com
>>>
>>> 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 android-developers@googlegroups.com
>>> To unsubscribe from this group, send email to
>>> android-developers+unsubscr...@googlegroups.com

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

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

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

Re: [android-developers] Reliable way to programmatically open options menu on startup

2010-09-26 Thread Mark Carter
I think all these methods are called on the main thread, so this shouldn't
be an issue.

On 26 September 2010 14:23, Prakash Iyer  wrote:

> would he also need to synchronize the threads? else in the thread that he
> is displaying the options he might have checked the boolean and then just
> before he calls his function to display the onStop could have got called in
> the other thread? possible?
>
>
> On Sat, Sep 25, 2010 at 6:38 PM, Dianne Hackborn wrote:
>
>> isFinishing() is not what you want, that tells you if you have called
>> finish().  The activity can be destroyed for other reasons, such as a
>> configuration change.  Just implement onStop() to set a flag to say not to
>> open the menu.
>>
>>
>> On Sat, Sep 25, 2010 at 3:11 PM, Mark Carter wrote:
>>
>>> Yeah, I was trying to remember why I posted it delayed - and I think its
>>> because I was having the problem without the delay.
>>>
>>> I suppose, even if the post is not delayed, the user might still back out
>>> before the openOptionsMenu gets to the front of the queue.
>>>
>>> Thanks - yeah, maybe use isFinishing() and possibly override it to set a
>>> flag when super.isFinishing() returns. isFinished() would have been nice!
>>>
>>>
>>> On 25 September 2010 23:48, TreKing  wrote:
>>>
 On Sat, Sep 25, 2010 at 3:11 AM, Mark Carter wrote:

> Is there any way to avoid this?
>

 Don't post it delayed? It's probably happening if a user clicks your app
 to open it, then decides it was a mistake and tries to exit immediately
 after, so the Activity is exiting by the time your Runnable runs.


> Maybe a test to see whether the activity is still running? If so, what
> is the most reliable way to do that?
>

 Maybe "isFinishing()"?


 -
 TreKing  - Chicago
 transit tracking app for Android-powered devices

  --
 You received this message because you are subscribed to the Google
 Groups "Android Developers" group.
 To post to this group, send email to
 android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en
>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To post to this group, send email to android-developers@googlegroups.com
>>> To unsubscribe from this group, send email to
>>> android-developers+unsubscr...@googlegroups.com
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-developers?hl=en
>>>
>>
>>
>>
>> --
>> Dianne Hackborn
>> Android framework engineer
>> hack...@android.com
>>
>> 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 android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

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

Re: [android-developers] Reliable way to programmatically open options menu on startup

2010-09-26 Thread Prakash Iyer
would he also need to synchronize the threads? else in the thread that he is
displaying the options he might have checked the boolean and then just
before he calls his function to display the onStop could have got called in
the other thread? possible?

On Sat, Sep 25, 2010 at 6:38 PM, Dianne Hackborn wrote:

> isFinishing() is not what you want, that tells you if you have called
> finish().  The activity can be destroyed for other reasons, such as a
> configuration change.  Just implement onStop() to set a flag to say not to
> open the menu.
>
>
> On Sat, Sep 25, 2010 at 3:11 PM, Mark Carter wrote:
>
>> Yeah, I was trying to remember why I posted it delayed - and I think its
>> because I was having the problem without the delay.
>>
>> I suppose, even if the post is not delayed, the user might still back out
>> before the openOptionsMenu gets to the front of the queue.
>>
>> Thanks - yeah, maybe use isFinishing() and possibly override it to set a
>> flag when super.isFinishing() returns. isFinished() would have been nice!
>>
>>
>> On 25 September 2010 23:48, TreKing  wrote:
>>
>>> On Sat, Sep 25, 2010 at 3:11 AM, Mark Carter wrote:
>>>
 Is there any way to avoid this?

>>>
>>> Don't post it delayed? It's probably happening if a user clicks your app
>>> to open it, then decides it was a mistake and tries to exit immediately
>>> after, so the Activity is exiting by the time your Runnable runs.
>>>
>>>
 Maybe a test to see whether the activity is still running? If so, what
 is the most reliable way to do that?

>>>
>>> Maybe "isFinishing()"?
>>>
>>>
>>> -
>>> TreKing  - Chicago
>>> transit tracking app for Android-powered devices
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To post to this group, send email to android-developers@googlegroups.com
>>> To unsubscribe from this group, send email to
>>> android-developers+unsubscr...@googlegroups.com
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-developers?hl=en
>>
>>
>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com
>
> 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 android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

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

Re: [android-developers] Reliable way to programmatically open options menu on startup

2010-09-25 Thread Dianne Hackborn
isFinishing() is not what you want, that tells you if you have called
finish().  The activity can be destroyed for other reasons, such as a
configuration change.  Just implement onStop() to set a flag to say not to
open the menu.

On Sat, Sep 25, 2010 at 3:11 PM, Mark Carter  wrote:

> Yeah, I was trying to remember why I posted it delayed - and I think its
> because I was having the problem without the delay.
>
> I suppose, even if the post is not delayed, the user might still back out
> before the openOptionsMenu gets to the front of the queue.
>
> Thanks - yeah, maybe use isFinishing() and possibly override it to set a
> flag when super.isFinishing() returns. isFinished() would have been nice!
>
>
> On 25 September 2010 23:48, TreKing  wrote:
>
>> On Sat, Sep 25, 2010 at 3:11 AM, Mark Carter wrote:
>>
>>> Is there any way to avoid this?
>>>
>>
>> Don't post it delayed? It's probably happening if a user clicks your app
>> to open it, then decides it was a mistake and tries to exit immediately
>> after, so the Activity is exiting by the time your Runnable runs.
>>
>>
>>> Maybe a test to see whether the activity is still running? If so, what is
>>> the most reliable way to do that?
>>>
>>
>> Maybe "isFinishing()"?
>>
>>
>> -
>> TreKing  - Chicago
>> transit tracking app for Android-powered devices
>>
>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Reliable way to programmatically open options menu on startup

2010-09-25 Thread Mark Carter
Yeah, I was trying to remember why I posted it delayed - and I think its
because I was having the problem without the delay.

I suppose, even if the post is not delayed, the user might still back out
before the openOptionsMenu gets to the front of the queue.

Thanks - yeah, maybe use isFinishing() and possibly override it to set a
flag when super.isFinishing() returns. isFinished() would have been nice!

On 25 September 2010 23:48, TreKing  wrote:

> On Sat, Sep 25, 2010 at 3:11 AM, Mark Carter wrote:
>
>> Is there any way to avoid this?
>>
>
> Don't post it delayed? It's probably happening if a user clicks your app to
> open it, then decides it was a mistake and tries to exit immediately after,
> so the Activity is exiting by the time your Runnable runs.
>
>
>> Maybe a test to see whether the activity is still running? If so, what is
>> the most reliable way to do that?
>>
>
> Maybe "isFinishing()"?
>
>
> -
> TreKing  - Chicago
> transit tracking app for Android-powered devices
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

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

Re: [android-developers] Reliable way to programmatically open options menu on startup

2010-09-25 Thread TreKing
On Sat, Sep 25, 2010 at 3:11 AM, Mark Carter  wrote:

> Is there any way to avoid this?
>

Don't post it delayed? It's probably happening if a user clicks your app to
open it, then decides it was a mistake and tries to exit immediately after,
so the Activity is exiting by the time your Runnable runs.


> Maybe a test to see whether the activity is still running? If so, what is
> the most reliable way to do that?
>

Maybe "isFinishing()"?

-
TreKing  - Chicago
transit tracking app for Android-powered devices

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

[android-developers] Reliable way to programmatically open options menu on startup

2010-09-25 Thread Mark Carter
The first time a user ever runs my app, I show the options menu by
doing something like this in Activity.onCreate():

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
openOptionsMenu();
}
}, 500);

However, using analytics, I can see that very occasionally (< 1% of
the time) openOptionsMenu() throws this exception:

android.view.WindowManager$BadTokenException: Unable to add window --
token null is not valid; is your activity running?

I've tried catching this exception, but then other exceptions follow.

Is there any way to avoid this? Maybe a test to see whether the
activity is still running? If so, what is the most reliable way to do
that?

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