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

40
Android mobilių programėlių kūrimo įvadas

Upload: tadas-jurelevicius

Post on 02-Jul-2015

312 views

Category:

Education


1 download

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

Page 1: "Android" mobilių programėlių kūrimo įvadas #2

Androidmobilių programėlių kūrimo įvadas

Page 2: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 3: "Android" mobilių programėlių kūrimo įvadas #2

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

Page 4: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 5: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 6: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 7: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 8: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 9: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 10: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 11: "Android" mobilių programėlių kūrimo įvadas #2

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).

Page 12: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 13: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 14: "Android" mobilių programėlių kūrimo įvadas #2

Intents and Intent Filters

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

Page 15: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 16: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 17: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 18: "Android" mobilių programėlių kūrimo įvadas #2

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).

Page 19: "Android" mobilių programėlių kūrimo įvadas #2

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).

Page 20: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 21: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 22: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 23: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 24: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 25: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 26: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 27: "Android" mobilių programėlių kūrimo įvadas #2

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.

Page 28: "Android" mobilių programėlių kūrimo įvadas #2

Setup IDE

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

Page 29: "Android" mobilių programėlių kūrimo įvadas #2

Create Android project

Page 30: "Android" mobilių programėlių kūrimo įvadas #2

Create Android project

Page 31: "Android" mobilių programėlių kūrimo įvadas #2

Android project structuresrc – Java code

assets – external files

libs – external libraries

res – application resources

AndroidManifest.xml – the "manifest" file

Page 32: "Android" mobilių programėlių kūrimo įvadas #2

MainActivity.java

Page 33: "Android" mobilių programėlių kūrimo įvadas #2

activity_main.xml / strings.xml

Page 34: "Android" mobilių programėlių kūrimo įvadas #2

Hello world Result

Page 35: "Android" mobilių programėlių kūrimo įvadas #2

Create Result Activity Manifest file

Page 36: "Android" mobilių programėlių kūrimo įvadas #2

Create Result Activity

Page 37: "Android" mobilių programėlių kūrimo įvadas #2

Update Main Activity

Page 38: "Android" mobilių programėlių kūrimo įvadas #2

Update Main Activity

Page 39: "Android" mobilių programėlių kūrimo įvadas #2

Update Main Activity

Page 40: "Android" mobilių programėlių kūrimo įvadas #2

Q&A

[email protected]