Java source files. This is where you will add your code. Organized in subfolders according to the different parts of the package name (reverse domain name).
Optional raw data files that the application might need. Not handled by the platform in any way.
Extra libraries with code that the application mgith need.
Important resource files in both xml and binary (images) format. These files are handled and selected by the platform according to different properties (qualifiers) of the device.
Main configuration of the application. Specifies all activities of the application, some names, the icon, permissions and more.
Important objects in an application
The basic object of all Android applications. Without an Activity, nothing will be displayed on the screen. An application must contain at least one Activity, but can contain more.
The basic visual object when building the user interface. All specific visual components are derived from the View. Can be buttons, input fields, formatted text, images etc.
A special View that contains other Views layed out on screen according to some rule/specification. Usually a ViewGroup-derived layout class is the root of your user interface.
Describes an action that should be performed, most often in the form of starting an Activity.
Not so important objects
The root object of your application. Must always exist, and there will only be one. You can derive your own class from the Application class if you want to handle something application specific, but we will not need to do that in this course.
The Window object handles a top level View for an application. The Window contains a View, but can also handle a title and some more visuals. You rarely or never need to access the Window of your application.
Generalization of the resources and other objects that relates to the application. You will use it as an argment in many calls, but you don't need to know anything more about it and you can always use the Activity (this) for the course's examples.
Configuration/definition files below the "res" folder of your project
Mostly binary files (like jpg) or xml files
Each subfolder below "res" has a special meaning to the platform
We'll talk more about resource files in the next chapter
User interface specification
Stored as xml files below the "layout" subfolder
We'll edit this file in our first project
Stored as xml files below the "string" subfolder
We'll get back to these in the next chapter
Your first Activity
Visual appearence - layout
Defined in res/layout/main.xml
Specifies elements to show in the user interface
Java Class where your code/logic resides
Stored in src/se.mobileapplab.demo/MainActivity.java
Contains code that will be called by the platform when events happen
Separation of layout/code is quite similar to how ASP.NET separates between an aspx-file and a code-behind file
Layouts in an Activity
This is the default type of layout for new projects
Every visual element is placed in relation to some other/previous element
We'll always change this to LinearLayout for the examples in this course
A little less powerful and less efficient than the RelativeLayout
But I think it is easier to use and understand
All visual elements are either layed out horisontally or vertically
Nested LinearLayouts can be used for more complex layouts
Until next chapter, we'll use it like this
Vertical orientation for elements below each other
All child elements are full width and height according to contents
Views in a layout
Simple text content
android:text is the content
Button that can be pressed
android:onClick is name of Activity method to call when pressed
Method can have any valid Java name, but must be void and take View argument
Methods in an Activity class
Some methods have predefined names which makes them into event handlers
Event handlers are called by the Android platform during the life cycle of an Activity
Event when the application is created for the first time. Initialize all variables here. Read any stored data from persistant storage. The onCreate of your first (single?) Activity can be thought of as the main method of your whole application.
Access to a visual element from your Java code
You often need to change visual elements from Java
Give the visual element an id in the xml layout file
Declare an object in your class with same name as visual element
Set object to refer to the visual element in onCreate using findViewById
Use a reference to a visual element
Change the text of a TextView
Most attributes in the xml have corresponding set-methods for changing them from Java
However, some are a bit more difficult to set/change (like android:layout_width)
Start other application
Android has something similar to file extension associations
Applications can register to handle different types of "actions". Such a specification is called an "Intent" on Android. By using Intents, you don't need to know about which other applications are installed on the device but still take advantage of their features from your application.
Create an Intent object with an Action (and optional specification)
Launch other application with startActivity
Start the dialer with a prepared phone number
Start the messaging app to a prepared phone number with a text
Call a phone number immediately. Requires the CALL_PHONE permission!
Start the web browser and go to web site
Use the web browser to search for something
Share a text to any registered application (like Facebook)
The configuration xml file for the whole application
Activities in the application
The permissions the application requires to run
System events that the application can handle (Intents and Broadcast receivers)
This is where the display name of the application can be changed
Editable in Eclipse via helper forms, or in its raw xml form (last tab in Eclipse)
Android Permission system
Applications define permissions that they require in the manifest
Never require more permissions that you actually need
User will see these permissions before confirming to install application
Permissions are an all-or-nothing option. If the user isn't confident with the requested permission(s), the user can only select NOT to install the application at all.