..


Sponsored Links

The Activity

In the previous chapter we have presented three of the four components making up an Android application. We are now going to present the most significant and important component: the 'actvity.

The peculiarity of an activity, which makes it different from all other components, is to have a 'graphical interface.
An example of an activity is a list of clickable buttons in a menu application that allows a user to perform different actions depending on the button clicked. Obviously an application may have more activity, for example, you might think to create an activity that shows a menu screen of the device and other activity that manage the behavior of the various buttons on the Steamer.

Since an application may be multiple activity, which are delegated to a specific task, it is clear that each activity is independent of the others. It 'must, however, identify a sort of hierarchy of activities, in fact, in our case we would like the activity containing the menu is displayed immediately when the application is launched and possibly other Activities start only when the user clicks on a button of menu. To do this you need to mark the activity as a primary screen that displays the menu (we'll see how the sample applications).

But what is the area of ​​action of an activity? By default, the activity can work on the whole window screen, but it is not forbidden to restrict the area of ​​action to force the activity to work only at certain points of the window.

Usually the elemnti graphics in the interface are managed by a hierarchy of view which have the task of managing well-defined rectangular spaces belonging to the window. So it is up to detect a possible view of the touch by a user on a particular graphic within its competence.

Life cycle of an activity

All the components we have shown above have their own life cycle that shows how to change the state of the system dall'istanziazione component to its elimination from the memory. In this section we will focus exclusively on the life cycle of an activity.

First of all identify the various states in which an activity can be found once instantiated:

  • Active: In this state the activity is shown in the foreground on the screen and the user can interact with the GUI shown.
  • Idle: The activity will still be displayed on the screen, but the user can not interact with it because another activity was superimposed on the primary. A classic example is when a call is received on the activity where the call is superimposed on the application that the user was using.
  • Stoppata: it falls in this state when the activity is completely overlapped by another, and thus is no longer visible to the user. In fact, the initial activity is hidden to the user and if the memory is running low Android will close the hidden activity.

Lists the states where you can find an activity is appropriate to present the reader with the transitions as methods that allow the passage from one state to another:

  • void onCreate ()
  • onStart void ()
  • onRestart void ()
  • onResume void ()
  • onPause void ()
  • void OnStop ()
  • onDestroy void ()

We will see later how to use these transitions in the examples that will be proposed during the discussion.

Help develop applications for Android
E-Learning
Flash MX (Advanced) Flash MX (Advanced)
Become a designer of Web sites from 29 €.
Web Design (Course) Web Design (Course)
Design Web Sites with HTML, CSS and Dynamic HTML. From 39 €.
Webmaster Base (First) Webmaster Base (First)
Create a Web site from scratch. Starting from 29 €.
Sponsored Links