1. Please talk about the architecture of the Android system.
A: The Android system uses a tiered architecture, from the high-level to the lower-level, which are application tiers, application framework tiers, System runtime tiers, and Linux core tiers.
2. Talk about the five types of layouts commonly used by Android.
For:
There are five layouts in Android, namely: Framelayout (frame layout), LinearLayout (linear layout), Absolutelayout (absolute layout), relativelayout (relative layout), Tablelayout (table layout).
(1) Framelayout frame layout, where all elements are placed in the leftmost area, and cannot specify an exact position for these elements, the next child element overlaps the previous child element, suitable for viewing a single picture
(2) LinearLayout linear layout, which is the most commonly used layout in the application, mainly provides a horizontal or vertically arranged model of the control, each of which is positioned in a vertical or horizontal way. (Default is vertical)
(3) Absolutelayout absolute positioning layout, the use of axis positioning components, the upper left corner is (0,0) point, to the right x axis increment, down the y axis, the component positioning properties of android:layout_x and android:layout_y to determine the coordinates.
(4) Relativelayout relative layout, depending on the other component or the top-level parent component to determine the location of the next component. Similar to the inside of CSS.
(5) Tablelayout table layout, similar to table in HTML. Use TableRow to lay out, where TableRow represents a row, and each view component of TableRow represents a cell.
3. Talk about how the Android data is stored.
For:
Android provides 5 ways of storing data:
(1) using sharedpreferences to store data; it is a mechanism provided by Android to store some simple configuration information, using XML format to store data in the device. Can only be used within the same package and cannot be used between different packages.
(2) file storage data; File storage is a more common method, the method of reading/writing files in Android is exactly the same as the program implementing I/O in Java, providing Openfileinput () and Openfileoutput () method to read the file on the device.
(3) SQLite database stores data; SQLite is a standard database with Android, it supports SQL statements, it is a lightweight embedded database.
(4) Use ContentProvider to store data, primarily for data exchange between applications, enabling other applications to save or read the various data types of this content provider.
(5) Network storage data, upload (store) and download (obtain) The data we store in cyberspace through the storage space provided to us on the network.
4.Android activity, Intent, Content Provider, service each have what difference.
For:
Activity: Active, is the most basic Android application component. An activity is a separate screen, and each activity is implemented as a separate class and inherits from the active base class.
Intent: Intention to describe what the application wants to do. The most important part is the data corresponding to the action and the action.
Content Provider: An android application can save their data to a file, a SQLite database, or even any valid device. Content providers can work when you want to share your app data with other apps.
Service: A program that has a long life cycle and no user interface.
5.View, Surfaceview, Glsurfaceview What's the difference.
For:
View is the most basic and must be updated within the main thread of the UI to be slow.
Surfaceview is a subclass of view, similar to using a double-slow mechanism to update the screen in a new thread so that the refresh interface is faster than the view
Glsurfaceview is a subclass of Surfaceview, OpenGL-specific
What is the role of 6.Adapter? What are the common adapter?
For:
Adapter is the adapter interface that connects the backend data to the front-end display.
Common adapter are arrayadapter, Baseadapter, CursorAdapter, Headerviewlistadapter, ListAdapter, Resourcecursoradapter, Simpleadapter, Simplecursoradapter, Spinneradapter, Wrapperlistadapter, etc.
What information is included primarily in the 7.manifest.xml file?
For:
Manifest: Root node that describes all the contents of the package.
Uses-permission: Ask for the security license you need to give your package a normal operation.
Permission: A security license is declared to limit which programs can be components and features in your package.
Instrumentation: Declares the code used to test this package or other Packages directive component.
Application: Contains the root node of the application level component declaration in the package.
Activity:activity is the primary tool for interacting with users.
Receiver:intentreceiver enables the application to obtain data changes or actions that occur even if it is not currently running.
Service:service is a component that can run at any time in the background.
Provider:contentprovider is a component used to manage persisted data and publish it to other applications.
8. Write a piece of code (SAX, DOM, or pull) to parse the XML document.
Answer: Here is the XML file to parse:
Zhang 322
John Doe
Define a JavaBean named person to hold the XML content parsed above
public class Person {
Private Integer ID;
private String name;
private short age;
Public Integer getId () {
return ID;
}
public void SetId (Integer id) {
This.id = ID;
}
Public String GetName () {
return name;
}
public void SetName (String name) {
THIS.name = name;
}
public short getage () {
return age;
}
public void Setage (short age) {
This.age = age;
}
}
(1) Read an XML file using sax, which uses event-driven, and does not need to parse the entire document, fast and consumes less memory. A class that implements the ContentHandler interface needs to be provided for sax.
Persondefaulthandler.java
Import java.util.ArrayList;
Import java.util.List;
Import org.xml.sax.Attributes;
Import org.xml.sax.SAXException;
Import Org.xml.sax.helpers.DefaultHandler;
Import Com.sinber.domain.Person;
public class Persondefaulthandler extends DefaultHandler {
private List persons;
private person person; Record current person
Private String Pertag; Record the name of the previous label
/**
* Overrides the start document method of the parent class. Used to initialize
*/
@Override
public void Startdocument () throws Saxexception {
persons = new ArrayList ();
}
@Override
public void Startelement (string uri, String localname, String qName,
Attributes Attributes) throws Saxexception {
if ("Person". Equals (LocalName)) {
Integer id = new Integer (attributes.getvalue (0)); Take ID
person = new person ();
Person.setid (ID);
}
Pertag = LocalName;
}
/** Parameters:
* CH Entire XML string
* The index position of the start node value in the entire XML string
* Length of the value of the length node
*/
@Override
public void characters (char[] ch, int start, int length)
Throws Saxexception {
if (pertag!=null) {
String data = new string (ch,start,length);
if ("Name". Equals (Pertag)) {
Person.setname (data);
}else if ("Age". Equals (Pertag)) {
Person.setage (new short (data));
}
}
}
@Override
public void EndElement (string uri, String localname, String qName)
Throws Saxexception {
if ("Person". Equals (LocalName)) {
Persons.add (person);
person = null;
}
Pertag = null;
}
Public List getpersons () {
return persons;
}
}
Saxperson.java
Import Java.io.InputStream;
Import java.util.List;
Import Javax.xml.parsers.SAXParser;
Import Javax.xml.parsers.SAXParserFactory;
Import Com.sinber.domain.Person;
public class saxperson{
public static List Getperson () throws exception{
Obtaining a file from a class loader
InputStream instream = SAXPersonService.class.getClassLoader (). getResourceAsStream ("person.xml");
SAXParserFactory factory = Saxparserfactory.newinstance ();
SAXParser saxparser = Factory.newsaxparser ();
Persondefaulthandler handler = new Persondefaulthandler ();
Saxparser.parse (instream, handler);
Instream.close ();
return Handler.getpersons ();
}
}
(2) When the DOM parses an XML file, it reads all the contents of the XML file into memory, and then allows you to use the DOM API to traverse the XML tree and retrieve the data you need.
Domperson.java
Import Java.io.InputStream;
Import java.util.ArrayList;
Import java.util.List;
Import Javax.xml.parsers.DocumentBuilder;
Import Javax.xml.parsers.DocumentBuilderFactory;
Import org.w3c.dom.Document;
Import org.w3c.dom.Element;
Import Org.w3c.dom.Node;
Import org.w3c.dom.NodeList;
Import Com.sinber.domain.Person;
public class Domperson {
public static List Getperson () throws exception{
List pers = new ArrayList ();
InputStream instream = SAXPersonService.class.getClassLoader (). getResourceAsStream ("person.xml");
Documentbuilderfactory factory =documentbuilderfactory.newinstance ();
Documentbuilder builder = Factory.newdocumentbuilder ();
Document dom = Builder.parse (instream);
Element root = Dom.getdocumentelement ();
NodeList persons = Root.getelementsbytagname ("person");
for (int i=0;i<persons.getlength (); i++) {
Element Personnode = (Element) persons.item (i);
person person = new person ();
Person.setid (New Integer (Personnode.getattribute ("id")));
NodeList childNodes = Personnode.getchildnodes ();
for (int j=0;j<childnodes.getlength (); j + +) {
Node Childnode = Childnodes.item (j);
if (Childnode.getnodetype () ==node.element_node) {
element element = (element) Childnode;
if ("Name". Equals (Childnode.getnodename ())) {
Person.setname (New String (Element.getfirstchild (). Getnodevalue ()));
}else if ("Age". Equals (Childnode.getnodename ())) {
Person.setage (New Short (Element.getfirstchild (). Getnodevalue ()));
}
}
}
Pers.add (person);
}
Instream.close ();
return pers;
}
}
(3) Reading an XML file using the Pull parser
Pullperson.java
Import Java.io.File;
Import Java.io.FileOutputStream;
Import Java.io.InputStream;
Import java.util.ArrayList;
Import java.util.List;
Import Org.xmlpull.v1.XmlPullParser;
Import Org.xmlpull.v1.XmlSerializer;
Import android.os.Environment;
Import android.util.Xml;
Import Com.sinber.domain.Person;
public class Pullperson {
public static void Save (List persons) throws exception{
XmlSerializer serializer = Xml.newserializer ();
File File = new file (Environment.getexternalstoragedirectory (), "person.xml");
FileOutputStream OutStream = new FileOutputStream (file);
Serializer.setoutput (OutStream, "Utf-8″");
Serializer.startdocument ("Utf-8″, true);
Serializer.starttag ("", "persons");
for (person Person:persons) {
Serializer.starttag ("", "person"); Person
Serializer.attribute ("", "id", "" +person.getid ());
Serializer.starttag ("", "name"); Name
Serializer.text (Person.getname ());
Serializer.endtag ("", "name"); Name
Serializer.starttag ("", "Age"); Age
Serializer.text (Person.getage (). toString ());
Serializer.endtag ("", "Age");//age
Serializer.endtag ("", "person"); Person
}
Serializer.endtag ("", "persons");
Serializer.enddocument ();
Outstream.close ();
}
public static List Getpersons () throws exception{
List persons = NULL;
person person = null;
Xmlpullparser parser= Xml.newpullparser ();
InputStream instream = PullPersonService.class.getClassLoader (). getResourceAsStream ("person.xml");
Parser.setinput (instream, "Utf-8″");
int eventtype = Parser.geteventtype (); Trigger the first event
while (eventtype!=xmlpullparser.end_document) {
Switch (eventtype) {
Case Xmlpullparser.start_document:
persons = new ArrayList ();
Break
Case Xmlpullparser.start_tag://Start Element event
if ("Person". Equals (Parser.getname ())) {
person = new person ();
Person.setid (New Integer (Parser.getattributevalue (0)));
}else if (person!=null) {
if ("Name". Equals (Parser.getname ())) {
Person.setname (Parser.nexttext ());
}else if ("Age". Equals (Parser.getname ())) {
Person.setage (New Short (Parser.nexttext ()));
}
}
Break
Case Xmlpullparser.end_tag://End Element Event
if ("Person". Equals (Parser.getname ())) {
Persons.add (person);
person = null;
}
Break
Default
Break
}
EventType = Parser.next ();
}
return persons;
}
}
Choose one of the above three options.
9. Describe the Android digital signature according to your own understanding.
For:
(1) All applications must have a digital certificate, the Android system will not install an application without a digital certificate
(2) The digital certificate used by the Android package can be self-signed and does not require an authoritative digital certificate Authority signature Authentication
(3) If you want to formally publish an Android, you must sign the program with a digital certificate generated by a suitable private key, instead of using the ADT plugin or the debug certificate generated by the Ant tool to publish.
(4) Digital certificates are valid, and Android only checks the validity of the certificate when the application is installed. If the program is already installed on the system, it does not affect the normal functionality of the program, even if the certificate expires.
10. The head structure of the single-linked list head, write a function to reverse the list.
A: as shown below
Node.java
public class Node {
Private Integer count;
Private Node NextNode;
Public Node () {
}
public Node (int count) {
This.count = new Integer (count);
}
Public Integer GetCount () {
return count;
}
public void SetCount (Integer count) {
This.count = count;
}
Public Node Getnextnode () {
return nextnode;
}
public void Setnextnode (Node nextnode) {
This.nextnode = NextNode;
}
}
Reversesinglelink.java
public class Reversesinglelink {
public static node Revsinglelink (node head) {
if (head = = null) {//list empty cannot reverse order
return head;
}
if (Head.getnextnode () ==null) {//If there is only one node, of course the inverse is the same.
return head;
}
Node Rhead = Revsinglelink (Head.getnextnode ());
Head.getnextnode (). Setnextnode (head);
Head.setnextnode (NULL);
return rhead;
}
public static void Main (string[] args) {
Node head = new node (0);
Node Temp1 = NULL,TEMP2 = null;
for (int i=1;i<100;i++) {
Temp1 = new Node (i);
if (i==1) {
Head.setnextnode (TEMP1);
}else{
Temp2.setnextnode (TEMP1);
}
Temp2 = Temp1;
}
Head = Revsinglelink (head);
while (Head!=null) {
Head = Head.getnextnode ();
}
}
}
Android Pen Test set 2