Free Android app covering all aspects of addiction, including prevention and treatment

Using Threads Tutorial

Forget the grass, get off the Main thread!

Android threads tutorial icon

Have you read the article on Processes and Threads yet?

Always remember the two most important rules when working with threads:

  • Don’t block the Main thread
  • Don’t try and access the UI directly from the worker thread

Speed up your apps response times. Move all processing and I/O operations off the main thread. Do the work in a child thread. Our tutorial will show you how.

The parent's in control

fragments tut part3 icon

We only have one activity in our app. It hosts the fragments.

If you haven't already done so, have a look at :

We’re using the support library so make sure that you import the correct class:

fragment tut part2 icon

We'll build the two fragments in this part of the tutorial.

If you haven't already done so, have a look at :


fragmentsTut part1 icon

Our tutorial app has one activity and two fragments. One fragment contains a list and the other an image.

Running the app on a small device in portrait mode, displays the list fragment. Selecting an item in the list displays the second fragment containing an image.

Flipping the device to landscape displays both fragments side by side.

Running the app on a tablet displays the fragments side by side in both portrait and landscape mode.

 

Notification iconMaster the basics of Android notifications

Notifications inform the user about something. They appear in the Notification area at the top of the screen.

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.

Connect your Android device to your computer and simply copy the diy_quiz.txt file that you created to your device's Download folder.

You can also email the file to yourself by adding it as an attachment to the email message. Then open the email on the device and save the file. It should automatically be saved to the device's Download folder.

Remember that the file must be in the Download folder as the Diy Quiz app will only look for the file in this folder

  1. Open up an OpenOffice spreadsheet.
  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.
  4. Save the file. Select File > Save As from the main menu. Then from the drop down screen:  enter diy_quiz.txt as the File name: and select Text CSV (.csv)(*.csv) as the Save as type: option. "Un-select" the Automatic file name extension box and select the Edit filter settings box. Press the Savebutton to save the file.
  5. In the next pop-up screen, press the Keep Current Format button.
  6. Then, in the next pop-up window, select Unicode (UTF-8) as the Character set, enter the "pipe" character (|) as the Field delimeter and leave the Text delimeter field blank (delete whatever is in there). Press OK.
  7. That's it. You're done.

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.

    1. Open up a LibreOffice spreadsheet.
    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 th category (or subject), followed by a question. You then need to supply the correct answer followed by four more possible (but incorrect) answer. Each of these fields are separated by the "pipe"character.
    4. Save the file. Select File > Save As from the main menu. Then form the drop down window:enter diy_quiz.txt as the File name: and select Text CSV (.csv) (*.csv) as the Save as type: option. Clear the Automatic file name extension box and tick the Edit filter settings box. Click the Savebutton.
    5. In the next pop-up screen, select the Use Text CSV Format button.
    6. Then, in the next pop-up window, select Unicode (UTF-8) as the Character set, enter the "pipe"character (|) as the Field delimiter and clear the Text delimeter field. Press OK.

That's it! You're done.

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.

Android for beginners. Building a Fuel Consumption Calculator with line by line commentary is aimed at those wanting to develop Android applications without having to dig through piles of technical jargon. It helps you build a working Android application step by step, with line by line commentary explaining each line of code. fuelCover


After working through the tutorial you will have a good understanding of Android application development and will be able to go on to build more complex applications with confidence.

The Consumption Calculator covers all the basics of an interactive Android applications. On first installation it displays a splash screen which checks whether or not a vehicle registration has already been saved. A Main menu then displays, allowing the user to either add a record, edit a record, delete a record or calculate the fuel consumption. The record contains the vehicle registration number, date of entry, odometer reading, total fuel bought and the total cost of the fuel. The record is saved in a Sqlite database.

The database can be searched by date or odometer reading to find a record or to calculate the fuel consumption between two dates or odometer values.

The tutorial takes you step by step, building the project, creating the activities and layout files. Explaining each step, describing each line of code.

You can download all the project files of the working application to validate your progress.

A must have resource for anyone wanting to learn Android application development. 

Available at Amazon.com