Basic Android knowledge

Source: Internet
Author: User

Android features:

  • Application FrameworkEnabling reuse and replacement of components
  • Dalvik Virtual MachineOptimized for mobile devices
  • Integrated BrowserBased on the open source WebKit Engine
  • Optimized graphicsPowered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional)
  • SQLiteFor Structured Data Storage
  • Media SupportFor common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, Amr, JPG, PNG, GIF)
  • GSM telephony(Hardware dependent)
  • Bluetooth, edge, 3G, and WiFi(Hardware dependent)
  • Camera, GPS, compass, and accelerometer(Hardware dependent)
  • Rich Development EnvironmentIncluding a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE

Framework:

Application Components:

  • Activity
  • Services
  • Content Providers
  • Broadcast receiver er

Manifest File

The function list of the entire program, including package definition, version declaration, application activity, icon, service, intent filter, and other declarations.

In eclipse, you can use the manifest editor to conveniently edit the file (right-click it ).

<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest...>
<Application...>
<Activity Android: Name = "com. example. Project. freneticactivity"
Android: icon = "@ drawable/small_pic.png"
Android: Label = "@ string/freneticlabel"
...>
</Activity>
...
</Application>
</Manifest>

Activities and tasks

A task is the "application" that the user feels. A task is a stack composed of a group of associated activities (these activities may belong to multiple applications ). the bottom of the stack is the first activity displayed when the application starts. The stack top activity is the activity you see on the screen. When an activity starts a new activity, the new activity is pushed into the stack. When you click the "back" button, the activity at the top of the stack will be popped up. For example, assume that the task has two activities, namely a and B, and a is the activity at the top of the stack. After you click "back", A is popped up, B becomes a new stack top activity, and activity B is displayed on the screen.

Generally speaking, the activities in the task stack will not be changed in the order of arrangement, but only the operations of the out stack and in the stack.

A task is a stack of activities, not a class or an element in the manifest file. so there's no way to set values for a task independently of its activities. values for the task as a whole are set in the root activity. for example, the next section will talk about the "affinity of a task"; that value is read from the affinity set for the task's root activity.

All the activities in a task are moved as a whole-Move to the front-end and back-end. In this example, assume that the current task stack has abcd4 activity, and a is the activity on the top of the stack, that is, the activity displayed on the screen. The user clicks the "home" key, when a new application is started, all four activities of ABCD will be moved to the background. After a while, the user clicks the "home" key and selects the previous program again, the ABCD is moved to the foreground, and A is still displayed on the screen as the stack top activity, then, the user clicks "back". Stack a is displayed, and activity B is displayed on the screen as the new stack top activity.

All of the above are the default actions of tasks. We can change the default actions of tasks in some ways.

The activity in different tasks is composedAffinityBy default, the activities in each task have the same affinity. However, you can use the taskaffinity attribute in the <activity> label to modify the affinity of an activity. You need to set the flag_activity_new_task flag and set the allowtaskreparenting attribute to true. This document explains: As described earlier, a new activity is, by default, launched into the task of the activity that calledstartActivity(). It's pushed onto the same stack as the caller. However, if the intent object passedstartActivity()ContainsFLAG_ACTIVITY_NEW_TASKFlag, the system looks for a different task to house the new activity. often, as the name of the Flag implies, it's a new task. however, it doesn' t have to be. if there's already an existing task with the same affinity as the new activity, the activity is launched into that task. if not, it begins a new task.

Note: When the flag_activity_new_task attribute (similar to singletask and singleinstance) is used, it cannot be rolled back to the caller.

There are four main loading methods for an activity in a task.:
1. Standard (the default mode): After an intent is sent, a new activity is generated to respond to this intent;
2. singletop: The activity at the top of the stack. that is to say, if an intent is processed by the activity at the top of the stack, a new activity will not be created, but will be processed by the original activity;
3. singletask: a new task will be created for this activity. That is to say, a New Affinity will be allocated for this activity;
4. singleinstance: identical"singleTask", And ensure that this activity is unique.

Since there are some provisions on the initial loading process, there will naturally beSome methods to end the process:
When acitivity exits, it will inevitably affect the stack of the task. Therefore, Android also defines the acitivity behavior.
1. alwaysretaintaskstate attribute. Ensure that the stack remains unchanged. By default, if a task is not active for a long time, it degrades to the root activity, that is, the stack is popped up, and only one acitivity at the bottom is retained.
2. cleartaskonlaunch attribute. This will clear the stack of the task during acitivity loading.
3. finishontasklaunch attribute. to some extent, this attribute ensures that a task is unique. this is because when a similar task is loaded, if this attribute is true, it will first exit the previous Task and then load the task.

If the flag_activity_clear_top attribute is true, all activities on the activity Stack are cleared at the end of the activity. flag_activity_clear_top is most often used in conjunction with flag_activity_new_task. when used together, these flags are a way of locating an existing activity in another task and putting it in a position where it can respond to the intent.

Related Article

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.