Sunday, February 23, 2014

Learn Android in 20 concepts: Concepts 1 and 2 - The Free Android

android development

Last week we announced

new section Learn Android in 20 concepts section oriented introduce us to the basics start our own application program Android .

In fact, apart from the 20 concepts , include a point last week 0 of introduction, where we could settle development environment and have our machine ready to start programming .

Today we speak of the first two concepts: an application Basics and Resources

.

1. Fundamentals of an application

The first thing to mention is that Android applications are written in the programming language object-oriented Java . The Android SDK has a number of tools that will compile the code, including data and resources (which we’ll discuss below), and will get you all in one APK file , or also known as Android package . This file will be our installer.

After installing an application, each has its own security system in such a way that:

  • Each application is a different user within Android as Operating System based on Linux multiuser system . This user will be a unique Linux user ID.
  • Android
  • give permissions to all files in an application only for the user that identifies this app.
  • Each process has its own virtua machine l, so that application execution is completely independent.
  • By default, each application runs in its own Linux process , which manages OS-level

android architecture

With all these rules, Android gets implementing what is known as lower Principle privilege , of giving the right permissions to each application, so that the system is as safe as possible.

android lock

But this is the default behavior, as we manage as we are interested, for example to share data between different applications (a perfect example is the Contacts).

Once known as

runs Android, it’s time to move on to define the components of an application . These are the building blocks that we can build. There are 4 different types of components:

  • Activity : represents a separate screen with a user interface . Although our application will have multiple screens interconnected, we are to generate them individually and independently (can pass data between them, if necessary). Get into more detail in this class when we get to Concept 3.
  • Service : It is a component that runs line for lengthy operations or work in remote processes . Contrary to the activity, no GUI. We will get more details in line 11.
  • Content Provider: This component allows us manage a set of application data sharing . Contacts are the perfect example for this component: we can share data between different applications. But we can create our own set of data (more detail on the concept 13).
  • Broadcast Receiver : The fourth component allows us to respond to ads broadcast system . A good example is if we manage when we get the low battery warning (which will send a message broadcast ), though we can design our own posts (more details on the concept 8).

An interesting design aspect of Android is that one application could open to a component of an application B. The perfect example is when we want to use the camera in our app, we can make an Activity with the camera, or open the camera component which is installed by default in the operating system.

We use a message called Intent , which also serves to activate 3 of the 4 components of an app (all except the Content Provider), Looking ahead No specific methods how to open any component through an Intent (concept 7).

android app components

But know how our application which components are available? For this, there AndroidManifest.xml file . This file will be responsible to inform the operating system:

  • components available to the application
  • permissions necessary for the application (camera, GPS …)
  • Android version

  • minimum necessary
  • hardware and software required and / or used
  • using external libraries (like Google Maps …)

AndroidManifest

For this, use tags, which in the case of the components are:

Each of these labels have a number of attributes, which will indicate which component in question will be all available, icon or endless options available. Furthermore, if we mean the capacity of one of our components, we can use the label .

2. Resources of an app

resources

when making a good program if you have to outsource resources code , meaning resources images, texts, styles … In this way, we can also specify different resources depending the type of device in which we are, without modifying the code . For this, the perfect example is the mobile version of the same tablet and screen (or Activity to go jargon entering ): create a single Activity which uses a different distribution of their content according to the type of device we use.

layouts

can always specify a generic resource or default. In contrast to this, we will have the option specify that a particular version of a resource is for a specific configuration .

detailing the specific configuration languages ??can build on, resolution, device orientation … It is enough to see the possibilities in this page. Basically lies add terminations to the folders where we will store resources commensurate to the specific configuration .

All resources under the folder will / res. But what are the resources that can include? The following:

  • Animations
  • Colors
  • Images ( Drawable )
  • Layouts (layout graphic elements)
  • Menus
  • Text Strings (String )
  • Styles
  • Other (boolean, dimensions …)

They must be in a specific folder structure , so that for example to add strings in Spanish would use the folder / res / values-en or / res / drawable-xxhdpi for drawables for high-resolution displays.

Here you can see a flowchart of how Android selects the appropriate resource:

application workflow

Taking

clear how resources are managed, how do we create some specific resources? Let’s look at some of them. Layouts, menus and styles

layout defines the visual structure of a user interface. Although we could dynamically create it by code, ideally declare interface elements in XML .

To create a layout, we have many graphical components already in the API, but we can create our own. We insert layouts where multiple components, text views, buttons … Here you can see an example of a layout that will put us a text and a button just below:

layout example

In this case, we put a LinearLayout elements one after the other (in this case when its vertical orientation, one below the other). Below is a TextView that occupies the width and height you need (wrap_content) , with text Hello, I am a TextView . And similarly for the button. Each with its unique identifier.

If we want to get good at making layouts, ideally start working with the graphic editor eclipse or Android Studio , but go checking how is the XML. As time passes, you will realize that sometimes be faster write directly in XML.

When will define

menu in one of our activities, it is also defined through a XML. For more information, I recommend visiting the link. Here you have an example:

menu example

Finally, when we talk about styles , we are referring a the closest thing to what CSS is for a web concept outsource styles to be reused. We can define styles to assign to graphic entities and create a topic to assign the entire application.

Here you can see how to display text in a specific format:

text style

as remains after use with unique style where CodeFont could reuse in other Views, or if we decided to change it, we could change it all at once:

styled text

Having reached this point, I think it is time to mention to guide interface design for Android, a website where you can see trends and tips on how to ride a good user interface.

Finally, to play around with the allocation of resources to different configurations, would be well that you should follow this example of Google.

With this we terminate the first two concepts in this section. It is true that these two concepts are very dense, they are concepts which pretend to explain the structure of the application , but many of the things that are named will analyze a posteriori.

Ready for the following items?

Learn Android

See section 20 concepts

No comments:

Post a Comment