Storing Local Data

So far, we've concentrated on writing applications that don't need to keep data around when they exit. They start up, run, and go away, leaving no trace that they were ever there. However, most real programs need persistent state, whether it's a simple font size setting, an embarrassing photo from your last office party, or next week's meal plan. Whatever it is, Android lets you permanently store it on your mobile device for later use and protects it from accidental or malicious access by other...

Drawable

In Android, a Drawable class is used for a visual element like a bitmap or solid color that is intended for display only. You can combine drawables with other graphics, or you can use them in user interface widgets for example, as the background for a button or view . Drawables can take a variety of forms NinePatch A stretchable PNG image, so named because originally it divided the image into nine sections. These are used for the background of resizable bitmap buttons. Shape Vector-drawing...

Continuing an Old Game

At any time the player can decide to quit playing our Sudoku game and go do something else. Maybe their boss walked in, or they got a phone call or a notification of an important appointment. Whatever the reason, we want to allow the player to come back later and continue where they left off. First we need to save the current state of the puzzle somewhere. The preferences API can be used for more than just options it can store any small stand-alone bits of information that go with your program....

I Joe Asks 1

Shouldn't We Use a Background Service for Music We haven't said much about the Android Service class, but you may have seen it used in some music-playing examples on the Web. Basically, a Service is a way to start a background process that can run even after your current activity finishes. Services are similar to, but not quite the same as, Linux daemons. If you're writing a general-purpose music player and want the music to continue while you're reading mail or browsing the Web, then, yes, a...

Creating an AVD

To do this, you need to create an Android Virtual Device AVD using either Eclipse or the android avd command.6 It's easier to use Eclipse, so select Yes in the AVD Error dialog to open the AVD Manager. You can open the manager again later by selecting Window gt Android SDK and AVD Manager. 6. Creates a new Android Project resource. Create project from existing source 13 Use default location Location C Development wo rkspa ce-''H el 1-oAndrord Create project from existing sample Standard Android...

Applying Texture

Although the scene is starting to look more interesting, nobody would mistake it for real life. Everyday objects have textures, like the rough surface of a brick wall or the gravel on a garden path. Do you own a laminated table A wood laminate is just a photograph of wood grain that is glued on the surface of a less expensive material like plastic or particle board. The first version of this example kept track of the current rotation angle and simply incremented it each time through the loop....

I Joe Asks Jmt

Is Allowing JavaScript to Call Java Dangerous Whenever you allow a web page to access local resources or call functions outside the browser sandbox, you need to consider the security implications very carefully. For example, you wouldn't want to create a method to allow JavaScript to read data from any arbitrary path name because that might expose some private data to a malicious site that knew about your method and your filenames. Here are a few things to keep in mind. First, don't rely on...