Just based on the source code that you have shown, in addition to
Kostya's suggestion, here are the changes that I would make:

1. Call startActivity() before finish().

2. Use the Intent constructor that takes your Java class object as the
second parameter, and get rid of the setClassName() call (as that will
no longer be needed).

3. Delete the Activity_GameScreen constructor, as you do not implement
constructors on activities. Moreover, it should not matter how many
Activity_GameScreen instances are constructed -- at most, you care how
many instances of Activity_GameScreen are put onto the screen (e.g.,
go through onCreate() and the rest of the lifecycle). Put logging in
onCreate(), not a constructor.

4. If Activity_GameScreen might already be running, consider adding
FLAG_ACTIVITY_REORDER_TO_FRONT to your Intent to bring the existing
activity to the foreground, rather than creating a new instance.

On Wed, Jul 18, 2012 at 9:31 AM, Mind <[email protected]> wrote:
> Debugged some more.  This is not a race condition.  Here is what I am
> seeing:
>
>         Log.i("WH", "TitleScreen: Starting new game");
>         finish();
>         Intent i = new Intent();
>         i.setClassName("com.blah",
> "com.rhs.wordhero.game.Activity_GameScreen");
>         startActivity(i);
>         Log.i("WH", "TitleScreen: Starting new game: Done");
>
> And in Activity_GameScreen:
>
>     public Activity_GameScreen()
>     {
>         Log.i("WH", "GameScreen Constructor");
>
> And my logs look like this:
>
> 07-18 09:26:33.762: I/WH(4338): TitleScreen: Starting new game
> 07-18 09:26:33.782: I/WH(4338): TitleScreen: Starting new game: Done
> 07-18 09:26:33.892: I/WH(4338): GameScreen Constructor
> 07-18 09:26:33.892: I/WH(4338): GameScreen onCreate
> 07-18 09:26:34.372: I/WH(4338): GameScreen Constructor
> 07-18 09:26:34.372: I/WH(4338): GameScreen onCreate
>
> So, it seems that the code is starting TWO copies of the new Activity.....
> Any ideas ?
>
>
>
> On Wednesday, July 18, 2012 2:50:57 AM UTC-4, Dianne Hackborn wrote:
>>
>> The log line you posted just means that for some reason your UI thread has
>> been busy so missed frames.
>>
>> If the code you printed is executing that log line more than once, then
>> you either have a race condition (because this is being executed from
>> multiple threads), or something is clearing that flag.  Either way, at this
>> point it looks like an issue in the app.
>>
>> On Tue, Jul 17, 2012 at 9:08 PM, Mind <[email protected]> wrote:
>>>
>>> 1st:  This does NOT occur on ICS.
>>>
>>> I have two Activities that I cycle between.  Game screen and Results
>>> screen (don't complain about not using Activity Fragments).
>>>
>>> I end one with finish() and then call the next.  If I exit out using the
>>> back button, some time later one of the Activies pops up.  Presumably
>>> because the timed game round ends and the next activity is auto-started or
>>> something.
>>>
>>> Additionally, I have a timer loop using Runnable.  Inside the loop I do
>>> things like this:
>>>
>>> if (game_time > 0 && game_time < 5 && flag)
>>> {
>>>   flag = false;    /// class variable
>>>   Log.i("WTF", "Why do I see this message more than once?");
>>> ... }
>>>
>>> Well, this code gets run MULTIPLE times.... I can see the log messages.
>>>
>>> If I upload the EXACT same APK to an ICS device, these behaviors do not
>>> happen.
>>>
>>> I also see this message in the log:
>>> 07-18 00:05:51.187: I/Choreographer(20425): Skipped 42 frames!  The
>>> application may be doing too much work on its main thread.
>>>
>>> Is anyone seeing anything similar or can explain this ?
>>>
>>>
>>> --
>>> 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
>>
>>
>>
>>
>> --
>> Dianne Hackborn
>> Android framework engineer
>> [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



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Training in DC: http://marakana.com/training/android/

-- 
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