Sunteți pe pagina 1din 5

Android Development Notes

Terminology
Android: a mobile operating system based on Linux Kernel. Designed for touchscreen mobile
devices like tablets and smartphones.
Applications: exist at the highest level, supports messaging, email and Internet browsing.
Application Frameworks: tools to create extensive rich graphical applications to users and deploy
these applications on Google Play.
Native Libraries: Compiled and pre-installed in C/C++ binaries that Android depends on.
Android Runtime: Components- core Java Libraries and Dalvik virtual machine
Dalvik Virtual Machine: Google’s implementation of Java optimised to be used on mobile
devices.
Linux Kernel: provides access to hardware as possible, internal radios, stereo and camera.
Project Structure
AndroidManifest.xml: android definition file, contains info about the android application like its
version, permission t access device capabilities and phone permissions.
Java: contains java code files.
Res: stores resource files such as pictures, XML files for defining layouts.
Drawable: images and icons
Layout: layout resource files
Menu:: menu items
Mip Map: pre-calculated, optimized collections of app icons by Launcher
Values: colors, dimensions, strings, and styles

App Fundamentals
Activity: building block of an Android App. It is the main entry point of an app. It interacts with
the user so it creates a window to place UI elements. It also can contain several activities for
many screens that interact with one another.
Activity Life Cycle: Activities are stored and managed in a stack called an activity stack. New
activity comes at the top of the stack and starts running while the previous activities remains
below. When the top activity in the stack exists, the lower to the top becomes active.
Methods of Cycle:
-onCreate(): called when activity is first created, all normal static set up create views, bind data
to lists. It provides a bundle containing activities previously frozen state.
-onRestart(): called after activity has been stopped, prior to being started again.
-onStart(): called when activity is becoming visible to user
-onResume(): called when an activity becomes visible to the user.
-onPause(): called when the system may start resuming a previous activity. Used to commit
unsaved changes to persistent data.
-onStop(): called when the activity is no longer visible to the user because another one has
resumed.
-onDestroy(): final call you receive before your activity is destroyed.
BroadCast Receiver: an app component that responds to system-wide broadcst announcements.
Called events or intents, applications can initiate broadcasts to let other applications know that
some data has been downloaded to the device and is available to use. This is the broadcast
receiver who will intercept this communication and will initiate appropriate action.
Content Provider: A component that supplies data from one application to another one upon
request. Handeled by the ContentResolver class through methods. A content provider manages
access to a central repository of data primarily intended to be used by other applications which
accesses the provider using a provider client object. The providers and provider clients offer a
consistent, standard interface to data that handles inter-process communication and secure data
access.
Service: A component which runs in the background without direct interaction with the user. As
the service does not have a user interface, it is not bound by the lifecycle of an activity. Services
are used for long and repetitive operations. A service life cycle using callback methods that
developers can implement to monitor changes in the service’s state.
Android Intent
Intents: asynchronous messages which allow application components to request functionality
from other Android components. They allow you to interact with components from the same
applications as well as with components contributed by other applications. Intents are used to
start services, startService(intent) method.
Explicit Intent: When creating an intent object, explicitly specify and pass on target component
name directly in the intent which is an explicit intent. An explicit intent is most commonly used
when launching an activity within the same application. Developers can also send data to another
activity by adding it to our intent in key-value pairs that can be retrieved by the receiving
activity.
Implicit Intent: Delegate the task of evaluating the registered components to Android based on
the intent data and the indenteded action that we pass. Android will automatically fire up the
component from the same app that can handle the intent message or job.
Big Nerd Ranch Text Notes
Layout: set of UI objects and their positions on the screen. A layout is made up of definitions
written in XML.
Android Studio: opens your project in a window. Tool Windows: different panes of the project
window. Left Hand view: project tool window – view and manage the files associated with your
project. Editor: main view.
UI
-Default activity layout defines widgets: Relative Layout and Text View
-Widgets: building blocks use to compose a UI. Widgets can show text or graphics that interact
with the user or arrange other widgets on the screen.
-Types of Widgets: buttons, text input controls and checkboxes.
-Every widget is an instance of the View Class or one of its subclasses.
-Each element has a set of XML attributes, each attribute is an instruction about how the widget
should be configured.
View Hierarchy
-View Hierarchy: widgets exist in a hierarchy of view objects.
Linear Layout: root element of this layout’s view hierarchy. Linear Layout must specify the
Android resource XML namespace. This inherits from a subclass of View named ViewGroup.
ViewGroup: a widget that contains and arranges other widgets. Use Linear Layout when you
want widgets arranged in a single column or row.
ViewGroup Subclasses: FrameLayout, TableLayout, and RelativeLayout.
-Child of ViewGroup: a widget contained by a ViewGroup. Root Linear Layout has 2 Children –
TextView and another LinearLayout. The child LinearLayout has 2 Button children of its own.
Widget Attributes
1. The android: layout_width & android: layout_height attributes are required for almost
every type of widget.
2. Match_parent: view will be as big as its parent
3. Wrap_content: view will be as big as its contents require
Root LinearLayout: value of height and width attributes is the match_parent. LinearLayout is the
root element but it has a parent, view that Android provides for app’s view hierarchy.
TextView: larger than the text its contains due to android:padding=”24dp” attribute. This
attribute tells the widget to add the specified amount of space to its contents when determining
its size.
-android:orientation attribute: on 2 Linear Layout widgets determines whether their children will
appear vertically or horizontally. The root LinearLayout is vertical, its child is horizontal.
-The order in which the children are defined determines the order which they appear on the
screen.
-Vertical LinearLayout: 1st child defined appear in topmost. Horizontal LinearLayout: 1st child
defined will be leftmost.
-android:text: Text attributes include TextView and Button widgets. The values of these
attributes are not literal strings, references to string resources.
String Resource: a string that lives in a separate XML file called a strings file.
-onCreateBundle method: called when an instance of the activity subclass is created. When the
activity is created, it needs a UI to manage it.
-public void setContentView(int layoutResID) method: inflates a layout and puts it on the screen.
-When a layout is inflated each widget in the layout file is instantiated as defined by its
attributes.

Resources
Resource: a piece of your application that is not code. Examples: image files, audio files, and
XML files. Layout is a resource.
-Resource ID: accesses resources for your project.
-Project View: located via he dropdown at the top of project tool window and change from
Android view to project view. This will show you files and folders in your project.
-Generate resource ID for a widget include android:id attribute in widget’s definition.
Wiring Widgets
-Button Widgets: get references to the inflated View Objects and set listeners on those objects to
respond to user actions.
References to Widgets
-Activity method: public View findViewById(int id): reference to an inflated widget
Setting Listeners
-Android applications are event driven, application is waiting for a specific event, listening for
that event.
-Listener: object that you create to respond to an event. The listener implements a listener
interface for that event.
Anonymous Inner Classes
Anonymous Inner Class: listener is implemented as this inner class. The anonymous class
implements OnClickListener must implement that interface’s sole method the onClickView.
Making Toasts --
-Toast: a short message that informs the user of something that may not require any input or
action.
-Toast Class: public static Toast makeToast(Context, context, int resId, int duration)
-Context Parameter: an instance of Activity. The second parameter is the resource ID of the
string that the toast should display. The context is needed by the Toast class to find and use the
string’s resource ID. The 3rd parameter is one of the 2 Toast Constraints that speciy how long the
toast should be visible.

S-ar putea să vă placă și