This week came into contact with Android, and finally figured out how to implement a simple app with Android-provided components. Some notes and tips are as follows:
"Four Components"
Activity, Service, ContentProvider, Broadcastreceiver
Activity |
The most common components are related to the page. An app is mostly composed of multiple activity. Exchange of information between activity with intent. |
ContentProvider |
Used for data exchange between different apps on a machine. An interface similar to external access provided by a service, which has the concept of a URI. Even if the app that provides the service interface does not start, other apps can delete and change the data. ContentProvider provides data in the form of a URI, and other apps use Contentresolver to specify data based on the URI to access the operation. Contentresolver can also receive notification of data changes by registering Contentobserver with ContentProvider. |
Service |
Very similar to activity. If you need an interface or need to interact with the user, then use the activity to do some backstage, long-time operations with the service. However, the normal service does not create new threads to do these operations. But as a special service,intentservice, a separate thread is created to handle more time-consuming tasks. The Aidl service defines the communication interface between different processes through the Aidl interface, so both the client and the server need to introduce such dependencies (Java RMI, or HSF, and so on) |
Broadcastreceiver |
A global listener. Other listeners can only rely on the original process, and the listener disappears after the original process exits. But the global listener has its own process, as long as there is a match intent is broadcast, Broadcastreveiver will always be fired. |
"Other Components"
Intent |
Used to exchange data in different activity in the same app. |
Message/looper /handler |
Handler sends a message inside a newly-started thread, typically getting a processing message inside the main path. The message is stored inside the MessageQueue and constructed by the Looper constructor MessageQueue. Each thread can have only one MessageQueue. If the main thread is not the main UI thread, you need to manually create a Looper object yourself. The loop method in Looper continuously polls the MessageQueue to take out the message. If the activity that created handler is finished, the Handlerd thread is also stopped and retracted. |
ANR exception |
Android No Response, performing operations that take a significant amount of time in the main thread can cause Android applications to fail to respond to input events and broadcast. |
asynctask< Params, Progress, result> "Generics" |
Used to perform work asynchronously. Creates an instance of Asynctask in the UI thread and invokes its Execute method. Method inside the Doinbackgroud (Params): Result;onpostexecute (Result): void; OnPreExecute (): void; Onprogressupdate (Progress): void needs to be rewritten by itself. In Doinbackgroun, you need to call Publishprogress (Progress): void to trigger onprogressupdate. |
Toast |
A simple message prompt box. The message does not get the focus, and after a while it disappears automatically (call Maketext to generate a Toast object, set properties such as Duration, call Show () method Display) |
"MVC"
In the most important androidmanifest.xml, you need to register all four components that are used.
Define the layout of the interface in each activity, including the elements (such as TextView, Button, and so on) by configuring the XML file
You can also modify related properties of these elements in your program, such as setting the text on button buttons.
"Listening and callback"
Similar to the JS way to implement the interface action trigger logic, such as the button is pressed to trigger that action. This is an interface program that must be implemented.
"Entry Difficulty"
Relatively simple, the Java Foundation plus some basic knowledge of the page design can be completed a simple demo APP. Of course, it's just a rough, weak kind of thing. To do well, in addition to knowing the basics of andriod, you also need specialized domain knowledge, preferably with UI skills. The most important thing is to get started! Of course there is a colleague or friend around you to help you solve some of the first easy to miss or not realize the small problem is better! Online there are a lot of demo source can see or follow the implementation, delete and change the tune, quickly can understand a so.
-----------------------------------------------------------
Come on! Stay fresh! Use code to realize your ideas!
-----------------------------------------------------------
Some concepts that Android beginners need to understand