An Error Occurs Starting an AVD That Previously Worked
When coding and running an App in the Eclipse Integrated Development Environment (IDE), debugging can be performed on an Android Virtual Device (AVD). You may see ERROR Unable to load VM from snapshot, one solution is to clear Launch from snapshot in the AVD Launch Options dialog, Note changes saved to the AVD will be lost. To access the launch options start the AVD from the Android Virtual Device Manager.
The error can occur with an AVD that previously ran without problems. It usually occurs after updating the Android Software Development Kit (SDK), via the Android SDK Manager program. It can also occur if the AVD configuration has been changed using the Edit option in the SDK Manager. When starting the AVD, or when pressing the Run button which attempts to start an AVD, the Starting Android Emulator dialog shows, it displays this error message (where Name-of-AVD is the chosen AVD): Starting emulator for AVD ‘Name-of-AVD’ emulator: ERROR: Unable to load VM from snapshot. The snapshot has been saved for a different hardware configuration.
If the virtual hardware upon which the emulator executes has changed then the saved virtual machine (VM) snapshot is no longer compatible with it. The virtual hardware can change if the hardware image has been updated by a new release of the Android SDK (updated by the SDK Manager), or the AVD configuration has been edited.
Fixing Error Unable to Load VM From Snapshot
A possible solution is to start the AVD fresh and not from a saved snapshot. Open the AVD Manager. Select the problem AVD from the list of existing AVDs. Select the Start button and the Launch Options dialog appears.
Click the Launch from snapshot check box to clear the tick before clicking the Launch button. The AVD starts from a fresh virtual machine image. Changes previously saved on the AVD are lost.
Occasionally you will still get an error launching the AVD. Delete the configured AVD and recreate it. (See Managing AVDs with AVD Manager.)
Writing Code for Different API Levels
How do you handle changes in the Android Application Programming Interface (API) in code? By placing code that uses changed APIs into a separate class, then wrapping the use of that class in a test. The test is comparing the device’s API level against the code’s target API level. The Build class provides the relevant version numbers to use in the test. However, there are other considerations in supporting multiple API versions. These factors are explored in this article.
New versions of Android provide new classes, additions to existing classes and deprecated classes and methods. (Deprecated classes and methods are those that are no longer required and will be removed in future releases.) These changes are due to the Android platform continuously evolving to take advantage of new hardware, new ideas and to improve performance.
Reference Documentation API Level Filter
The Android Reference documentation has details on all the classes in all the APIs. Each part of a class has a label to denote in which API level it first appeared. The API documentation can apply a filter based on API level to grey out the classes and parts of classes that were not available prior to a give API version.
The Android API Differences Report
To see an overview of the changes between an Android API level and the previous API release view the Android API Differences Report. The report is viewed online at the Android Developers web site. The address is http://developer.android.com/sdk/api_diff/X/changes.html where X is the API level to examine the differences from the previous level. For example if X is 9 then the differences report show the changes from API level 8 (Froyo) to API level 9 (Gingerbread). A link to each differences report is in the post Android Versions Numbering and API Levels.
Reading the Android Devices API Version
The API version used by an Android device is read from the static Build class in the android.os package. The Build.VERSION.SDK_INT returns the API level. The various API levels are defined in Build.VERSION_CODES.
For example here is some code to test for API level 9 (the first Android Gingerbread release):
The App running this code must have the minSdkVersion attribute in the manifest (AndroidManifest.xml) set to 4 (Donut) or higher. Prior to API level 4 SDK_INT was not available, it was Build.VERSION.SDK, a string. There are very few devices around early than API level 4 so setting the minSdkVersion to 4 or later should not be an issue, however, a workaround is discussed later.
Detect Other Android API Levels
The above code is easily extended to detected other API levels. So to detect API level 8, Froyo, the code becomes: Continue reading
When Hunting for Software Bugs Really Meant Getting Your Hands Dirty
Most modern programmers never need to get into the physical parts of a computer. We take computers for granted. Most of us walk around with a very powerful computer in our pockets. The smartphones of today are a relatively modern invention but are so ubiquitous that they are just part of normal life. A palm sized phone more powerful than the desktop computers of 10 to 20 years ago. If they go wrong they either get replaced or sent to specialist repairers. Many programmers will now have careers where the closest they get to the hardware is installing a micro SD card or SIM card in their phone. However, there was a time when debugging software was more than setting breakpoints in an IDE, you really had to know how computers worked at the hardware level and get into the machine.
Debugging Mode in the Old Days
It is good to look at how today’s technology evolved from past technology. It gives you a better understanding of why and how the modern technology operates. When pictures of old technology are viewed it reminds you of how far we have come in a short time frame. Computers have come a long way since their rapid evolution from the days after World War II. But it would not be until the 2000’s that they began to fit comfortably in the pocket. Yet computers used to need very large rooms. Here’s a picture from July 1961 of an IBM computer in the City Hall in Redmond, Virginia.
Even a computer this size was nothing more than a glorified calculator. They were good at counting and tabulating but not much else. When the programs failed it was not only the software that needed debugging. Often the hardware was the cause of the problem. In that case debugging mode meant opening the machine up to see which mechanical, electrical or electronic parts needed fixing or replacing. I wonder if the gentleman in this picture is in hardware debugging mode? BTW look at the size of the ducting over the machine, they used to use a stack of energy and generate a lot of heat. (And we moan about smartphones that need charging everyday.)
Next time you are struggling to debug your App or software think how much harder it used to be. It may help ease the pain 🙂
For the origination of the term software bug and possibly the first description of removing a real “bug” from hardware see Software bug on Wikipedia.
The photo was seen on Flickr Commons and is from the Adolph B. Rice Photograph Collection at the Library of Virginia.
Virtual Servers Have Cut IT Costs, Now Cut Overheads with Virtual Teams
When it comes to IT we live in a connected world. Communication is easier than it has ever been and modern IT devices (smartphones, tablets and computers) have communications as a prime function. This allows for new ways of working, flexible and always connected. This has given rise to companies that operate virtually. Teams can be spread out in wide geographical areas yet still work as if sitting in the same building. Consider the fact that when working on a project most of the time you are sat at your desk. Why waste time and resources bringing teams together each day when you can managing them remotely. When the project budget is tight save money by using self-employed engineers and organizing them using modern communications. Of course some projects will require traditional single location teams. It is about picking the best way to run a project for the bests results at the right cost.
Here are top 10 pointers for cutting IT costs using virtual teams. Continue reading
What is Business IT Alignment?
Most businesses and people use IT daily. It is now part of normal life. Many businesses depend on IT to operate and administer the day-to-day running. The buzz phrase for how well the IT systems helps the business is Business IT Alignment. What is Business IT Alignment? It is the process of changing the IT systems to ensure that they optimally serve the business process, and to make improvements in the business process by using the benefits that IT systems can bring. Here are top ten tips for business IT alignment. Keeping these tips in mind will ultimately reduce the long term running costs of a business. Continue reading
Load HTML Page Saved in Android Project
To display lots of informational text and images in an Android Application (App) HTML is a good choice. HTML is now at version 5 and supports text formatting and image display. The formatting of the text can be enhanced by applying CSS (Cascading Style Sheets). This article shows how to add HTML5 in Android using a simple example. The HTML file is created in an editor. The file is placed into the assets folder. An App with a WebView loads the HTML using the URL file:///android_asset/file.html, where file.html is the file created.
Create Files for HTML5 in Android App Example
To start the HTML5 in Android tutorial create a new Android App project in Eclipse or Android Studio (if you don’t know how see our Android Hello World Java Program example). Here the project is called Show HTML. The HTML to be displayed in this example will be an image and some text.
A new file is created in the projects assets directory. In Eclipse use the File menu to select New and then Untitled Text File. Enter the required HTML. (To see the basic structure of a HTML document look at the article Hello World in HTML.) In this tutorial the text used is a poem by Lewis Carroll from the book Alice’s Adventures in Wonderland. Any text can be used. The image of a crocodile was from the Open Clip Art Library and is in the Public Domain. Copy this image and save it into the assets directory as crocodile.png. Finally here’s the full text for this HTML example:
<title>Basic Web Page</title>
<h1>How Doth the Little Crocodile</h1>
<h2>by Lewis Carroll</h2>
<h2>from Alice's Adventures in Wonderland</h2>
<img alt="A green crocodile." src="crocodile.png"/>
<p>How doth the little crocodile<br/>
Improve his shining tail,<br/>
And pour the waters of the Nile<br/>
On every golden scale!<br/>
How cheerfully he seems to grin,<br/>
How neatly spreads his claws,<br/>
And welcomes little fishes in<br/>
With gently smiling jaws!</p>
Copy this HTML to the new file, save it in the assets directory and call it crocodile.html. (If using Android Studio you will need to create the assets directory under main in the project tree and name the HTML file first before adding the text.) Continue reading