Writing to and reading from files on your device

Part 1: You can bank on it: Saving files

Save files iconGot data to save?

Taking photos from within your app using the device's camera app

If you need to take a photo from within your app, just tap into the Camera app to do it for you.

Creating great launcher icons quick and easy!

Some stuff you need to know

All apps need a launcher icon.

Different images for different devices: it’s all about supply and demand

Android alternative bitmap resources logoThis is the 2nd part of a two part series of articles on designing Android apps for multiple screens. Here's a link to part 1, Different images for different devices: bitmaps, pixels and other things that go bump in the night

Put all images that you use in an Android app inside a drawable folder. You should also supply different size images for the different screen densities.

Alternative bitmaps

Android devices come in different shapes and sizes. Their screen sizes range from small phones to 10 inch tablets and larger TV’s. They also have different screen densities.

Different images for different devices: bitmaps, pixels and other things that go bump in the night

resources icon

Which images to use as image resources

There are two main graphic types, bitmap and vector graphics.

Vector graphics describe an image according to its geometric characteristics and can be resized without losing quality.

In Android, we’re more interested in Bitmap images which are stored electronically as a map of bits.

Another electronic image term is the pixel. Sometimes bits and pixels are interchanged and a bitmap can refer to a map of pixels, where each pixel represents a colour.

Bitmaps are resolution dependent which means they contain a fixed number of pixels so they will lose quality if you change their size.

Android ListView tutorial

Android ListView Tutorial

What’s a ListView

A ListView displays items in a vertical, scrolling list. It contains a number of views, one for each item in the list. Here’s an example:

Use SharedPreferences for persistant data

User Preference Settings

SharedPreferences are not the same as the typical user preferences where one, for example selects the preferred default sound, text size, colours, etc. for an app.

Using LogCat in Android Studio or Eclipse to debug your code

Android logcat icon

You’ve spent hours developing your app and each time you test it, it either bombs or returns results that you never expected. You would love to see what’s causing the problem. Well you can. Android’s Log class enables you to do just that. You can use the Log class to display messages as the app runs and even filter the messages so that only messages that you are interested in are displayed.

Comparing two dates in Android

I was busy doing some Android coding and needed to compare two dates. The result of the comparison had to show whether the dates were the same or whether one was greater than the other (or smaller). Having stored the dates as an integer in a SQLite database, I extracted and converted them into long objects. It was these long objects that I had to compare. 

As the long objects were accurate time stamps in milliseconds (including hours, minutes, seconds, and milliseconds), this posed a problem when comparing the dates as the same dates would not register as being equal if they differed by even a millisecond! The solution was to first convert them into a format that only represented the day, month and year.

    1. Open up WordPad
    2. Enter your questions, one per line. Separate fields with the "pipe" character (|). Do not use the pipe character anywhere else in your file. It is used to separate the fields.
    3. Keep the format -- category|question|correct answer|answer 2|answer 3|answer 4|answer 5  -- The first field is the category (or subject), followed by a question.You then need to supply the correct answer followed by four more possible (but incorrect) answers. Each of these fields are separated by the "pipe"character - see two questions in the image below:
    4. Save the file. From the drop-down menu select Save As > Plain Text Document
    5. Enter diy_quiz.txt as the File name. Select Text Document (*.txt) as the Save as type: and press the Save button.
    6. That's it!

You can have as many categories and questions as you like (although you probably won't want more than about 10 categories). The order in which you enter the categories doesn't really matter as long as you stick to the format (as described above) for each row. Remember that the trial version only shows two categories.

Once you've downloaded the text file to your device, it will be converted into a database by the app. If you choose to uninstall the app, it won't affect your text file which will remain in the device's Download folder.

You may find it easier using a spreadsheet to create your text file. OpenOffice and LibreOffice work fine and so should Microsoft Excel. I'll be posting how-to articles on the first two options here shortly.