
Note: To follow this tutorial, we consider that you know to create a new Android app with Android Studio.

To not our friend would suspect the joke, the service will add the image when the smartphone switches to standby. The display of the image of the broken screen must be through a program that has no GUI and is therefore not visible to the user. In our example, we use a service so that the user does not see our application running. In some cases, it is useful to create a program that runs in the background, without the application is visible, such as a music player (which works without the application open) or a timing system that performs actions at regular intervals. Why use a service in this tutorial Android ? The user therefore can not interact with it.

The big difference is an activity that has no GUI. As an activity, a service has a life cycle ( OnCreate (), OnStart ( Intent i) or OnStartCommand ( i Intent, int flags, int startId) and OnDestroy ()). A service, what is it?Ī service is a component that runs in the background. No stress, once your friend will unlock the smartphone, the false image disappear. He then discover its home screen with a false image of the broken screen.

Once the action taken, the application closes and nothing happens until the next use of the smartphone by your friend. The principle is simple, this application replaces the home screen of the smartphone with an image showing the broken screen.Īt launch, the application asks you to validate the joke by pressing the center button. To illustrate this concept little known and somewhat mysterious, we will create a small application to make a joke to your friends. We will learn through this Android tutorial how to use a “service” that runs in the background.
