Basic concepts for Android app development (Getting started)

Source: Internet
Author: User

Basic concepts of Android application development: Preface

Play games for nearly three years (mainly by the page and Hand tour), the beginning of this year, the company's business development needs to do Android, to now have studied 4 months, has been initially built to complete the company's SDK project, the project idle use the blog memo their early summary of some of the pre-summed up (things are not original from the Internet, blog , outline Memo), I do not like text long-winded, simple chart + short focus on the memo is a better way to remember (can quickly pull up their own memory, and then specific problems specific analysis), memo is nothing but a "process + focus"

"Small companies, now alone, if there are omissions or growth suggestions please Daniel pointed out!" Thanks, thanks! 】

1 Introduction to Android MVC:

    • Model objects: Data and business logic that stores the application "such as: Network, database, IO data, etc."
    • View objects: Know how to draw on the screen and how to respond to user input, such as user touch, such as: View, Viegroup, button and other components, XML file Interface description, WebView Html+css+js "
    • Control object: Contains the application logic unit, is the view and the Model object link "such as: Activity, Service, filter filters, etc."
2 Android Programming Fundamentals 2.1 Basic Components 2.1.1 Activity:

Activity is the control layer in which users interact with the UI
Start and life cycle:
The Android system launches code in the Activity instance by invoking a specific callback method corresponding to a specific stage in its life cycle. There is a series of callback methods that initiate activity, and a series of callback methods that decompose the activity.

Life cycle:

Activity state Transitions:

Three commonly used status situations:

Running:
In this state, the activity is in the foreground and the user can interact with it. (sometimes also called a "run" state.) )

Paused:
In this state, the activity is blocked in the foreground in a semitransparent state or another activity-that does not cover the entire screen. Paused activity does not receive user input and cannot execute any code.

Stopped:
In this state, the activity is completely hidden and invisible to the user, and it is considered to be in the background. When stopped, the activity instance and all state information, such as member variables, are preserved, but it cannot execute any code.

Activity Start Mode:
A, specify the initiator activity in the Mainfest.xml configuration such as:
··· Xml

2.1.2 Intent

A Intent is a message object, "Request + data" You can use to request some action from another app component.

Inten is mainly responsible for the handling of the operating system:

Basic Operations
Start a Activity:Context.startActivity (Intent Intent);
Start a Service:Context.startService (Intent service);
Bind a Service:Context.bindService (Intent service, serviceconnection conn, int flags);
Send a Broadcast:Context.sendBroadcast (Intent Intent);

two different types:
(1): Explicit intents (display).
Specifies the component that responds to this intent.

(2): implicit intents (implied intent)

The implied intent is not to declare the class name of the component to be started, but rather to declare the action to be performed. This action specifies the action you want to perform, such as viewing, editing, sending, or getting an item. Intent also typically includes the data associated with the action, such as the address you want to view or the e-mail message you want to send. Depending on the intent you want to create, the data may be a Uri, one of several other data types, or the intent may not require data at all, such as:

Uri number = Uri.parse("tel:5551234"new Intent(Intent.ACTION_DIAL, number);

Note : If you call the intent, but there is no app on your device to handle the intent, your app will crash
To confirm that there are available activity that responds to the intent, call Queryintentactivities () to get a list of the activity that can handle your intent. If the returned List is not empty, you can safely use the intent
"See the Internet match process in detail"

PackageManager packageManager = getPackageManager();List activities = packageManager.queryIntentActivities(intent,        PackageManager.MATCH_DEFAULT_ONLY);boolean0;
2.1.3 Context Provider

Content providers manages the use of structured data sets. They encapsulate data and provide a mechanism for data security. Content providers is a standard interface for connecting data from one process to another. Its primary role is not for data storage, but for providing data to external process apps. "If our address book data can be placed in Content providers medium"

official explanation : Its essence is the encapsulation of aidl

Content providers is one of the primary building blocks of Android applications, providing content to applications. They encapsulate data and provide it to applications through the single Contentresolver interface. A content provider is only required if you need to share data between multiple applications. For example, the contacts data are used by multiple applications and must being stored in a content provider. If you don ' t need to share data amongst multiple applications you can use a database directly via

2.1.4 Service

a Service is an application component that can run operations in the background without providing user interaction .

There are basically two forms of a service:
(1) Started
A service is turned on when an application component (such as an activity) calls StartService (). Once turned on, a service will always run in the background, even if the component that opened it has been destroyed. Typically, a service opens to perform a single operation and does not return a result to the caller.
For example: Download, upload, when an operation stops should destroy this service.
(2) Bound
A service is "bound" when an application component binds to the same service, "by calling Bindservice ()". A bound service provides Client-server interfaces that allow components and services to interact, send results, get results, and even access the IPC process. A bound service is the same as the run time of the component that binds it. When multiple components are a service, when all bindings are lifted, the service is destroyed.

2.2 Android Resource organization read and core file 2.2.1 Resource organization:

Android resources are divided into two broad categories, namely assets and RES

A. Assets. The Assets class resource is placed in the assets subdirectory of the project root, which holds some original files that can be organized in any way.
These files will eventually be packaged in the APK file in the original way. If we want to access these files in the program, we need to specify the file name to access.
For example, suppose you have a file named filename in the assets directory, then you can access it using the following code:

AssetManager am= getAssets();    is = assset.open("filename");  
    1. Res. The Res class resource is placed in the RES subdirectory of the project root, and most of the files stored in it will be compiled and will be given the resource ID. This allows us to access the Res class's resources through the ID in the program. Res class resources can be further divided into the following 9 seed types depending on their purpose:
      See MORE: Android website

Most of the files under the Res file are compiled by the AAPT Resource Pack tool (except under the Raw file) and generate the corresponding resource ID in the autogenerated r.java.
Access the specified resource through these ID represented in the program or resource file.

2.1.2 Resource adaptation options

2.2.3 Resource Packaging, read process:

2.2.4 Core Files:

Androidmainfest.xml
A androidmanifest.xml file must be included in the root directory of each app (and the file name is accurate). The manifest file provides the Android system with basic information about your app that the system must obtain to run any application code. In addition, the manifest file can perform the following actions.

Mainly includes:

    • Name the Java package for your app. The package name acts as a unique identifier for the app
    • Describes the various components of an app: Activity, service, broadcast sink, and content provider that make up your app. Name and publish the functionality of each component's class (for example, Intent messages that they can handle). According to these statements, the Android system can understand what this component is, and under what conditions they can be started
    • Identify the processes that will host the application components
    • Declaring what permissions an app must have to access protected portions of the API and interact with other apps
    • Also declares the permissions that other apps need to interact with the app component
    • Lists the instrumentation classes that provide analysis and other information while the app is running. These statements will only appear in the manifest file when the application is in the development and testing phase, and they will be deleted before the app sends a cloth.
    • Declare the minimum Android API level required for your app
    • List the libraries that the app must link to
2.3 User interface UI and common components and Events 2.3.1 Common components: (summary)
    • TextView:
    • Listview
    • Tost
    • EditText
    • Radiogroup
    • RadioButton
    • CheckBox
    • Spinner
    • DatePicker
    • Timepicker
    • Button
    • Menu
    • Dialog
    • ImageView
    • ImageButton
    • Imageswitcher
    • Gallery (Drag effect)
    • Autocomplete-textview,
    • Gridview
    • ScrollView,
    • ProgressBar
    • SeekBar
    • Notification
    • Notificationmanager (status bar hint)
    • ProgressDialog
Event distribution mechanism for 2.3.2 View:

2.4 Android Data storage 2.4.1 Shared Preferences

When the application is running, it may keep the user's configuration information as the user uses it, such as the EQ setting at the last play, the volume setting, the cookies information on the Internet, etc., which can be maintained by Sharedpreferences. Data persisted through Sharedpreferences as an XML file, located in the application's private folder

2.4.2 Files

In Android, you can create a file that holds data in the device's own storage device or from a storage device that is connected outside it. By default, files cannot be shared. Using files to store data can be
Openfileouput gets the file stream operation. (If the file does not exist, it will automatically create a file) through the loader method to go to the data in the file.

2.4.3 SQLite:

SQLite is an embedded relational database, supporting a size of 2T with the following characteristics
Lightweight: Small dynamic Connection Library after compilation
Independent: No reliance on third-party software
Cross-platform, multi-lingual interface support

2.4.5NetWork

Get and save resources through the network to write the server.

2.4.6 contentProvider2.5 Other 2.5 Android graphics rendering (Android game development)

Basic concepts for Android app development (Getting started)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.