"android" mobilių programėlių kūrimo įvadas #2

Post on 02-Jul-2015

312 Views

Category:

Education

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Antroji mokymų ciklo paskaita apie „Android“ operacinę sistemą, kurįa dėstė UAB „App Camp“ techninis projektų vadovas Vykintas Valkaitis. Paskaitos temos: 1. Pagrindiniai Android programos komponentai: - Activity - Service - Content Providers - Broadcast receiver - Fragment 2. UI koponentai: - Linear/Relative Layout - List View - Grid View - Button - Text View - Checkbox / Radio Button / Toggle Button 3. Drawables: - Paveiksliukai - 9 patch Image - State drawable - Animacija 4. Dialogai ir Toast 5. Stiliai ir temos 6. Duomenų saugojimas: - Shared Preferences - Internal Storage - External Storage - SQLite Database - Network Connection

TRANSCRIPT

Androidmobilių programėlių kūrimo įvadas

Application Fundamentals- Android applications are written in the Java programming language. - The Android operating system is a multi-user Linux system in which each application is a different user.- Each process has its own virtual machine (VM), so an application's code runs in isolation from other applications.

Application Components- There are four different types of application components. Each type serves a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed:

- Activity- Service- Content provider- Broadcast receiver

ActivityAn activity represents a single screen with a user interface. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails.

Activity Lifecycle

A representation of how each new activity in a task adds an item to the back stack. When the user presses the Back button, the current activity is destroyed and the previous activity resumes.

Activity LifecycleonCreate() - Called when the activity is first created. This is where you should do all of your normal static set up — create views, bind data to lists, and so on.

onRestart() - Called after the activity has been stopped, just prior to it being started again.

onStart() - Called just before the activity becomes visible to the user.

onResume() - Called just before the activity starts interacting with the user.

Activity LifecycleonPause() - Called when the system is about to start resuming another activity. This method is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, and so on. It should do whatever it does very quickly, because the next activity will not be resumed until it returns.

onStop() - Called when the activity is no longer visible to the user.

onDestroy() - Called before the activity is destroyed. This is the final call that the activity will receive.

FragmentA Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities.

Fragment LifecycleonAttach() - Called when the fragment has been associated with the activity.

onCreate() - The system calls this when creating the fragment.

onCreateView() - The system calls this when it's time for the fragment to draw its user interface for the first time.

onActivityCreated() - Called when the activity's onCreate() method has returned.

onStart(), onResume() - Same as Activity.

Fragment LifecycleonPause() - The system calls this method as the first indication that the user is leaving the fragment (though it does not always mean the fragment is being destroyed).

onStop() - Called when the Fragment is no longer started.

onDestroyView() - Called when the view hierarchy associated with the fragment is being removed.

onDestroy() - Called when the fragment is no longer in use.

onDetach() - Called when the fragment is being disassociated from the activity.

ServiceA Service is an application component that can perform long-running operations in the background and does not provide a user interface.

Started - A service is "started" when an application component (such as an activity) starts it by calling startService().

Bound - A service is "bound" when an application component binds to it by calling bindService().

A service runs in the main thread of its hosting process - the service does not create its own thread and does not run in a separate process (unless you specify otherwise).

Content ProviderA content provider manages access to a central repository of data. A provider is part of an Android application, which often provides its own UI for working with the data.

Decide if you need a content provider. You need to build a content provider if you want to provide one or more of the following features:- You want to offer complex data or files to other applications.- You want to allow users to copy complex data from your app into other apps.- You want to provide custom search suggestions using the search framework.

Broadcast receiversA broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured.

Intents and Intent Filters

Three of the core components of an application - activities, services, and broadcast receivers - are activated through messages, called intents.

User InterfaceAll user interface elements in an Android app are built using View and ViewGroup objects.

A View is an object that draws something on the screen that the user can interact with.

A ViewGroup is an object that holds other View (and ViewGroup) objects in order to define the layout of the interface.

User InterfaceAll user interface elements in an Android app are built using View and ViewGroup objects.

A View is an object that draws something on the screen that the user can interact with.

A ViewGroup is an object that holds other View (and ViewGroup) objects in order to define the layout of the interface.

Linear LayoutLinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute.

Linear Layout ExampleAll children of a LinearLayout are stacked one after the other, so a vertical list will only have one child per row, no matter how wide they are, and a horizontal list will only be one row high (the height of the tallest child, plus padding).

Relative LayoutRelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left of center).

Relative Layout ExampleRelativeLayout lets child views specify their position relative to the parent view or to each other (specified by ID). So you can align two elements by right border, or make one below another, centered in the screen, centered left, and so on. By default, all child views are drawn at the top-left of the layout, so you must define the position of each view using the various layout properties available from RelativeLayout.LayoutParams.

List ViewListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that's placed into the list.

Grid ViewGridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. The grid items are automatically inserted to the layout using a ListAdapter.

Input ControlsInput controls are the interactive components in your app's user interface. Android provides a wide variety of controls you can use in your UI, such as buttons, text fields, seek bars, checkboxes, zoom buttons, toggle buttons, and many more.

Buttons

Depending on whether you want a button with text, an icon, or both, you can create the button in your layout in three ways.

Text FieldsInput controls are the interactive components in your app's user interface. Android provides a wide variety of controls you can use in your UI, such as buttons, text fields, seek bars, checkboxes, zoom buttons, toggle buttons, and many more.

Text FieldsYou can specify the type of keyboard you want for your EditText object with the android:inputType attribute.

There are several different input types available for different situations. Here are some of the more common values for android:inputType:

"text" - Normal text keyboard."textEmailAddress" -Normal text keyboard with the @ character."textUri" - Normal text keyboard with the / character."number" - Basic number keypad."phone" - Phone-style keypad.

Checkboxes / Radio ButtonsCheckboxes allow the user to select one or more options from a set. Typically, you should present each checkbox option in a vertical list.

Radio buttons allow the user to select one option from a set. You should use radio buttons for optional sets that are mutually exclusive if you think that the user needs to see all available options side-by-side.

Setup IDE

http://developer.android.com/tools/

Create Android project

Create Android project

Android project structuresrc – Java code

assets – external files

libs – external libraries

res – application resources

AndroidManifest.xml – the "manifest" file

MainActivity.java

activity_main.xml / strings.xml

Hello world Result

Create Result Activity Manifest file

Create Result Activity

Update Main Activity

Update Main Activity

Update Main Activity

Q&A

v.valkaitis@appcamp.lt

top related