Professional Documents
Culture Documents
It creates a timer
that fires every 10 seconds, and also attempts to open the sensor,
which is represented by the TempeSensor class.
The onLayout() method is called when your app starts, and sets
up the layout of your app’s view. Because you’re only drawing
directly on the screen in the onUpdate() function, as opposed to
displaying UI elements whose contents are refreshed, you don’t
have any layout to perform. The dc argument is short for “draw‐
ing context,” which is an object that’s provided to your app for
all drawing operations. You want to put something on the
screen? You go through the dc.
The onShow() method is called when the app comes back into
the foreground. This restarts the timer (it will be stopped in
onHide()). This reveals a key part of power management. The
device runtime will notify your app when the user sends it to
the background. It does this by calling the onHide() method.
When the user returns to the app later, the device calls your
onShow() method.
This stops the timer when the app gets sent to the background.
See the preceding discussion for the onShow() method.