[android-developers] Touch screen response delay

2009-02-06 Thread Zombies and Robots

Hello.

I am working on a game that displays its graphics through a modified
SurfaceView.  The game scrolls around a map based on the location of
the main character.  That all works fine.

I am trying to add a feature to the game that allows you to touch the
screen and drag the camera around to see other parts of the map.  This
is where I am running into trouble.  The game's SurfaceView overrides
'public boolean onTouchEvent(MotionEvent event)' to call another
method in the game's thread which handles the events.  Sometimes, this
works fine (although the frame rate drops significantly while the
screen is touched).  Other times, there will be a delay of several
seconds before the game responds to a touch event, during which time
the game continues, but the user loses all control.  During these
delays, a message sometimes appears stating that my activity is not
responding, and giving the options to 'Force close' or 'Wait'.  If the
user selects 'Wait', the game almost always resumes right away, but
these delays are obviously not acceptable.

The delays occur only the first time the screen is touched after the
game is started.  Once the game has resumed after a delay, the touch
events work just fine again.

I have experimented with having the game thread sleep for short
periods at various points throughout the game.  Although this does
seem to have a small effect on the problem, the delays still happen.
Has anyone else run into this?  What am I doing wrong?

Thank you very much for any suggestions you can provide.

--~--~-~--~~~---~--~~
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] Re: Touch screen response delay

2009-02-08 Thread Zombies and Robots

I figured out what was causing my particular problem.  Both the method
that draws the SurfaceView and the method that handles the touch
events were synchronized with the same object.  I'm guessing the
delays were caused because the touch event handler method couldn't
access this object while the drawing method was running... which was
just about all the time.  To resolve the problem, all I had to do was
remove the synchronization from the touch event handler method and
modify my drawing method so that it accessed the camera's location
only once (which I would have done in the first place had I been
writing efficient code).

I'm feeling pretty dumb for missing that... but thank you nonetheless
for your helpful responses!  They definitely got me thinking toward
the solution.

On Feb 6, 7:58 pm, Al  wrote:
> Hi, have you checked the trace file that is written when an anr
> occurs? It shoud be in /data/anr with the filename traces.txt. This
> will show exactly what was running and at what line of code when the
> anr popped up and should help locate the problem code.
>
> On Feb 6, 7:03 pm, Zombies and Robots  wrote:
>
> > Hello.
>
> > I am working on a game that displays its graphics through a modified
> > SurfaceView.  The game scrolls around a map based on the location of
> > the main character.  That all works fine.
>
> > I am trying to add a feature to the game that allows you to touch the
> > screen and drag the camera around to see other parts of the map.  This
> > is where I am running into trouble.  The game's SurfaceView overrides
> > 'public boolean onTouchEvent(MotionEvent event)' to call another
> > method in the game's thread which handles the events.  Sometimes, this
> > works fine (although the frame rate drops significantly while the
> > screen is touched).  Other times, there will be a delay of several
> > seconds before the game responds to a touch event, during which time
> > the game continues, but the user loses all control.  During these
> > delays, a message sometimes appears stating that my activity is not
> > responding, and giving the options to 'Force close' or 'Wait'.  If the
> > user selects 'Wait', the game almost always resumes right away, but
> > these delays are obviously not acceptable.
>
> > The delays occur only the first time the screen is touched after the
> > game is started.  Once the game has resumed after a delay, the touch
> > events work just fine again.
>
> > I have experimented with having the game thread sleep for short
> > periods at various points throughout the game.  Although this does
> > seem to have a small effect on the problem, the delays still happen.
> > Has anyone else run into this?  What am I doing wrong?
>
> > Thank you very much for any suggestions you can provide.
--~--~-~--~~~---~--~~
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] IllegalThreadStateException when program is restored

2009-02-18 Thread Zombies and Robots

I'm hoping somebody who is more familiar with Android's application
life-cycle will be able to help me out here.

I'm writing a game.  From inside the game, I open a new activity (a
web browser window).  Once the user backs out of the browser window,
my game shows an error message and quits.  I imagine that this has
something to do with saving and restoring states, but the only errors
I receive are very vague, and they make it difficult to pinpoint the
problem.

For what it's worth, here is a stack trace from inside the Debugger:
Thread [<3> main] (Suspended (exception IllegalThreadStateException))
StealthView(SurfaceView).updateWindow(boolean) line: 362
StealthView(SurfaceView).onWindowVisibilityChanged(int) line: 173
StealthView(View).dispatchWindowVisibilityChanged(int) line: 3215
FrameLayout(ViewGroup).dispatchWindowVisibilityChanged(int) line:
675
FrameLayout(ViewGroup).dispatchWindowVisibilityChanged(int) line:
675
PhoneWindow$DecorView(ViewGroup).dispatchWindowVisibilityChanged(int)
line: 675
ViewRoot.performTraversals() line: 587
ViewRoot.handleMessage(Message) line: 1103
ViewRoot(Handler).dispatchMessage(Message) line: 88
Looper.loop() line: 123
ActivityThread.main(String[]) line: 3742
Method.invokeNative(Object, Object[], Class, Class[], Class, int,
boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 515
ZygoteInit$MethodAndArgsCaller.run() line: 739
ZygoteInit.main(String[]) line: 497
NativeStart.main(String[]) line: not available [native method]




And here is a second listing of the error from /data/anr/traces.txt:

Cmd line: com.android.stealth

DALVIK THREADS:
"main" prio=5 tid=3 NATIVE
  | group="main" sCount=1 dsCount=0 s=0 obj=0x400143a8
  | sysTid=317 nice=0 sched=0/0 handle=-1096602468
  at android.os.BinderProxy.transact(Native Method)
  at android.app.ActivityManagerProxy.handleApplicationError
(ActivityManagerNative.java:2023)
  at com.android.internal.os.RuntimeInit.crash(RuntimeInit.java:302)
  at com.android.internal.os.RuntimeInit
$UncaughtHandler.uncaughtException(RuntimeInit.java:75)
  at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:853)
  at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:850)
  at dalvik.system.NativeStart.main(Native Method)

"Binder Thread #2" prio=5 tid=13 NATIVE
  | group="main" sCount=1 dsCount=0 s=0 obj=0x433f1270
  | sysTid=322 nice=0 sched=0/0 handle=1263336
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #1" prio=5 tid=11 NATIVE
  | group="main" sCount=1 dsCount=0 s=0 obj=0x433eceb8
  | sysTid=321 nice=0 sched=0/0 handle=818312
  at dalvik.system.NativeStart.run(Native Method)

"JDWP" daemon prio=5 tid=9 VMWAIT
  | group="system" sCount=1 dsCount=0 s=0 obj=0x433ec2a0
  | sysTid=320 nice=0 sched=0/0 handle=811056
  at dalvik.system.NativeStart.run(Native Method)

"Signal Catcher" daemon prio=5 tid=7 RUNNABLE
  | group="system" sCount=0 dsCount=0 s=0 obj=0x433ec1e8
  | sysTid=319 nice=0 sched=0/0 handle=810600
  at dalvik.system.NativeStart.run(Native Method)

"HeapWorker" daemon prio=5 tid=5 VMWAIT
  | group="system" sCount=1 dsCount=0 s=0 obj=0x4253fda0
  | sysTid=318 nice=0 sched=0/0 handle=810328
  at dalvik.system.NativeStart.run(Native Method)


According to the Java documentation I've been able to find,
IllegalThreadStateExceptions occur when a program attempts to start a
thread that is already running.  I really don't see how my program
could be doing that.

Up until now, I've been able to figure out any problems I have had by
comparing my code to the example LunarLander and Snake source codes.
This problem has stumped me though.  I've been going back over this
problem for several hours now, and as far as I can tell, my code for
saving and restoring states uses exactly the same technique as
LunarLander.  What could I be doing wrong?

Many thanks to anyone with a suggestion!
--~--~-~--~~~---~--~~
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] Re: IllegalThreadStateException when program is restored

2009-02-18 Thread Zombies and Robots

Thanks for the responses!  I really appreciate the help!

I'm about to give the try/catch and logging idea a try.  I'll let you
know if I turn up anything.

I'll also post the code as soon as I'm able to.  I just have to move
it from the other computer.
--~--~-~--~~~---~--~~
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] Re: Get the name of the owner of the phone? (the email sender)

2009-02-18 Thread Zombies and Robots

I've been doing some research on this topic myself, but so far, I
haven't come up with anything.  It seems like a very simple question.

Does anyone else have an idea?

I'm going back to scouring the API...
--~--~-~--~~~---~--~~
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] Re: IllegalThreadStateException when program is restored

2009-02-18 Thread Zombies and Robots

After dissecting my code and playing around with the logs quite a bit,
I've determined that the problem starts when the activity's onResume()
is called, even though all that my overridden onResume() does is run
super.onResume().

There may be more to this.  I'll post more later.
--~--~-~--~~~---~--~~
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] Re: Touch *extremely* expensive performance-wise

2009-02-18 Thread Zombies and Robots

I am also developing games which may make heavy use of onTouchEvent(),
so this thread looks very helpful to me as well.

I've been trying to follow everything you guys have been talking
about, but I must admit that after trying several ways of implementing
what you suggest, I still haven't been able to achieve any positive
results.  Could one of you provide some example code?  Specifically,
I'd like to know how to go about making the main/UI thread sleep.  If
it's applicable to my games, it would also be nice to know how to set
up a polling model like Jon implemented.

Of course, I greatly appreciate any help!
--~--~-~--~~~---~--~~
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] Re: Touch *extremely* expensive performance-wise

2009-02-19 Thread Zombies and Robots

Thank you both!

With those pointers, I was able to figure out and implement working
versions of both techniques.  Now I just have to decide which one I
like better and finish writing my game...
--~--~-~--~~~---~--~~
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] Re: IllegalThreadStateException when program is restored

2009-02-22 Thread Zombies and Robots

AHA!

I *knew* I was doing everything just like LunarLander did.  I was!
That was the problem.

This particular bug was really bothering me.  I became a little
obsessed with it, so I tried logging practically everything that my
game did while it was running.  After lots of painstaking work, I
finally discovered the code that was to blame.

This is from my game's overridden SurfaceView class:

public void surfaceCreated(SurfaceHolder holder) {
   gameThread.setRunning(true);
   gameThread.start();
}

You'll notice that this method matches the corresponding method in
LunarView exactly.

The first statement in the method executes fine.  The
IllegalThreadStateException is thrown when gameThread.start() is
called.  I looked it up in the Java API and found out that this is
happening because gameThread is already in the Thread.State.TERMINATED
state when the statement is called.  The exception only occurs when
the game is being restored, because when the game is starting up for
the first time, gameThread is in the Thread.State.NEW state.

This didn't add up.  My program was doing everything just like the
example program that Google supplied.  Well, I checked, and it turns
out that the LunarLander program exhibits the same bug!

'Don't believe me?  Try it for yourself.  Send yourself a test text-
message, but don't open it.  Then open LunarLander.  While the game is
in progress, drag down the top menu bar, and click on the notification
that you have received a text.  This will open a new Activity and
cause LunarLander to save its state in the background.  Once you have
finished reading your text-message, press the 'back' button to resume
LunarLander.  This will cause LunarLander to attempt to restore its
state.  You should see an error message.

The same thing should also happen when someone calls you in the middle
of the game, or any time that another Activity is opened on top of the
game's Activity.

I've been trying to come up with some sort of workaround.  Perhaps
before calling gameThread.start(), I could check to make sure that
gameThread.getState() == Thread.State.NEW .  This works fine, but it
still leaves the problem of how to restart gameThread if the state is
not NEW.  I suppose I could just set gameThread to a new GameThread()
and try to start that, but that approach won't work because I need to
supply the Context for the GameThread, and that isn't passed to
surfaceCreated().

Is Google aware of this bug?  Does anybody know how to fix it?  Once
again, any help is greatly appreciated.
--~--~-~--~~~---~--~~
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] Re: IllegalThreadStateException when program is restored

2009-02-22 Thread Zombies and Robots

On Feb 22, 7:49 am, Mark Murphy  wrote:
> In the case of LunarLander, LunarView is a SurfaceView, which has
> getContext() to return the Context for the view.

Oh yeah--thanks!

I tried using getContext() to provide the context, and it seems to
work for the most part.  It's just frustrating that even the example
program suffers from this (somewhat critical) bug.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---