Using your application resources

Application Resources icon

You should keep your resources, like images, strings, values, etc. separate from your code.

Application Resources folders

Some of the folders in the res directory

Bound Services. A way to interact with the Service

andoid bound services tutorial icon

Our tutorial app uses a Service to play a sound clip.

We start a Service when the app starts. The Service will run as long as the app is alive.

We need to bind to the Service to start and stop playing a sound clip. We can leave the clip playing in the Service while it is running. It will continue to play even if the activity is paused or destroyed.

Bound Services: a primer

Android bound services tutorial icon

Quick recap on Services

  • Services are app components that you can use to do work in the background.
  • Services run in your app’s process in the main thread. Don’t block the main thread. Use a separate thread to do any heavy work in your Service.
  • You can also use Services running in another app’s process.
  • Services continue to run until you stop them. The system can also kill them at any time but you can set their priority so that they are unlikely to be killed.

So what happens when we bind to a Service?

Services Tutorial project filesOut in the open: The foreground Service

Android foreground service tutorial icon

It’s unlikely that the system will kill a foreground Service.

Typically we’d use foreground Services for work that the user is aware of, like playing music.

When we use a foreground Service, we have to send a notification to:

  • let the user know that the Service is running
  • give the user the opportunity to stop it

If you haven’t already done so, you may want to have a look at the article All about Services and Part 1 of the series of Services tutorials, A Simple Service

Doing it in the background. Services Tutorials. Part 1: A Simple Service

Android simple service tutorial icon

Our tutorial app shows you how to use Services to:

  • use a simple Service to update a user’s score on a server
  • use a foreground Service to play music in the background

There are two parts to the tutorial: Part 1 shows you how to use a simple Service and Part 2 shows you how to use a foreground Service.

All about Services

At your Service: Using Services

android services tutorial  icon

Services are app components that you can use to do work in the background. They don’t have a User Interface.

They are started and stopped by other components (like Activities, Broadcast Receivers and other Services).

You can also share Services with other apps.

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.

Processes and Threads

Android processes and threads tutorial

All Android apps run in their own process and by default, in a single thread.


It’s about multitasking

Android follows a multitasking design. This allows a number of applications to run at the same time. The problem is that all these apps need memory which is in short supply.

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 :