1. What are the operation types of databases and how do I import external databases?
- Data query (DQL) language basic form SELECT FROM WHERE
- Data manipulation (DML) language basic composition INSERT UPDATE DELETE
- Data definition (DDL) language basically constitutes the creation of the CREATE TABLE VIEW TABLE, attribute definition
- Data control (DCL) language is mainly used for database detection management (authorization, ROLLBACK (SQL>ROLLBACK;) , COMMIT data (COMMIT [WORK])
Database is the essence of the file, android system under the database should be stored in /data/data/com.. (package name)/ FileInputStream is used to copy files
if(! (newFile(dbfile).exists())) { InputStream is =this.context.getResources().openRawResource(R.raw.countries);
// The files under raw are the database to be imported and are saved in the project directory in advance
FileOutputStream fos =newFileOutputStream(dbfile);
byte[] buffer =newbyte[BUFFER_SIZE];
int count =0;
while((count = is.read(buffer)) >0) {
fos.write(buffer,0, count);
}
fos.close();
is.close();
}
Copy the code
2. Have you used local broadcast? What is the difference between global broadcast and local broadcast?
Local broadcasting First of all, why use local broadcasting? LocalBroadcastReceiver (broadcastreceiver) allows users to send and receive broadcasters only in their own applications. Broadcastreceiver allows users to receive broadcasters only in their own applications. The local broadcast mechanism is mainly introduced to solve security problems: 1. The broadcast being sent will not be separated from the application, so that the APP data leakage is worried; 2. 2. Other programs cannot be sent to their own applications and do not worry about security vulnerabilities. (For example: how to make an unkillable service – listening to popular apps such as wechat, Umeng, aurora broadcast, to boot themselves.) 3. Sending a local broadcast is more efficient than sending a global broadcast. Global broadcasting, meaning it can cross processes, requires low-level support. LocalBroadcastReceiver cannot be registered statically and can only be registered dynamically. LocalBroadcastReceiver use: (1) registered LocalBroadcastManager. GetInstance (this). RegisterReceiver (new XXXBroadCastReceiver (), new IntentFilter (action)); (2) the cancellation of registration: LocalBroadcastManager. GetInstance (this). UnregisterReceiver (receiver) 2: Global BroadcastReceiver is a mode of communication among applications, between applications and systems, and within applications. BroadcastReceiver can be registered statically or dynamically. BroadcastReceiver uses: (1) An intent (which can carry parameters) (2) sendBroadcast() (3) make BroadcastReceiver class inherit BroadcastReceiver to rewrite onReceive method (4) Register a broadcast receiver in Java (dynamic registration) or directly in the Manifest (static registration) using registerReceiver() and intentFilter (5) To cancel registration can be done in OnDestroy(), UnregisterReceiver () Incoming receiver
3. Have you used IntentService? What is it for?
Service, IntentService, AIDL
4. What is the difference between Activity, Window and View?
The Activity itself has no way of handling what controls to display (view). It is displayed through a PhoneWindow. In other words: The attach method is called when the activity is created: . 2, attach method will be called PolicyManager makeNewWindow () of the actual work is IPolicy interface makeNewWindow method (1), which creates a window (which can be compared to a house built on a window) : mWindow = PolicyManager.makeNewWindow(this); In the window class, setContentView() is called. This is the final call to the Activity’s setContentView method, which is actually called: getWindow().setContentView(view, params); GetWindow () gets a Window object tip: Attch takes precedence over onCreate because the attch method creates the window, and setContentView creates PhoneWindow. (1), by mWindow = PolicyManager. MakeNewWindow (this); ②, here makeNewWindow(this); Return sPolicy. MakeNewWindow (context); The sPolicy is actually an interface whose implementation class is Policy. PhoneWindow setContentView adds content to ViewGroup (root). PhoneWindow inherits from Windows SetContentView (); setContentView (); setContentView (); InstallDecor (), DecorView is the most hierarchyview.bat tool for viewing the structure of the phone via the Tools in ADT The mContentParent is not empty the next time it is loaded. The mContentParent is not empty the next time it is loaded. The mContentParent is not empty the next time it is loaded. 1. Call Attach in the Activity and create a Window. 2. Create PhoneWindow in attach. 3. Call setContentView(r.layout.xxx) from your Activity. Call PhoneWindow setContentView (); As a subclass of ViewGroup, DecorView(a subclass of FramLayout) is actually created. Fill the specified r.layout. XXX file with the layout filler Add a new view: addView() Fragment that can be used as part of the Activity interface. You can have multiple fragments in an Activity at the same time, and a Fragment can be used in multiple activities. You can add, remove, or replace fragments while an Activity is running. Fragments can respond to their own input events and have their own life cycles, which are influenced by the life cycle of the host Activity.
5. Describe the process of a network request
First of all, our browser does not know the domain name baidu.com… 2. Establish a TCP connection to the IP address of the host port to the destination IP address (for example, http://www… 3. Send data to the server. The browser encapsulates the network request into HTTP packets and subcontracts the HTTP packets through TCP. 4. The server parses the HTTP packet and determines what it requests based on the HTTP packet. Will deal with… Browsers load and display HTML from top to bottom, and render it from top to bottom… See more steps…
6. Differences between Handler, Thread, and HandlerThread
①Handler: in Android is responsible for sending and processing messages, through it can realize the message communication between other branch threads and the main thread. Thread: the smallest unit of execution in a Java process, which is the basic unit of execution processor scheduling. A program that runs alone in a process. (3) HandlerThread: A HandlerThread class inherits from Thread. Android does not encapsulate any Java threads. Instead, it provides a HandlerThread class inheriting from Thread. The original link
7. The lower version SDK implements the higher version API
Android gives us two ways to annotate to avoid compilation errors: @suppresslint @targetAPI What’s the difference between the two methods? SupressLint obviously means to ignore Lint checking, and for those of us using higher-version apis, we can use @suppressLint (“NewApi”) to make Lint ignore the version requirements of the called API at compile time. The @targetAPI error ignores a particular version of the API call. For example: when your project minSdkVersion=9 and you want to use the new method of API 11. At this point, using @targetAPI (11) will have the same effect as @SuppressLint(“NewApi”) and the code will not report an error. However, if you use a new method that just came out of Api 19, you will still get an error in the @targetAPI method and no error in the other method. So it’s better to use @suppressLint (“NewApi”)? Correct posture of course not! It is important to note that using the above two comments only prevents Lint from reporting errors at compile time. On older mobile systems, if you use older versions of the API directly, you will definitely report “NoSuchMethod” Crash. So the right thing to do is in the annotation method, do version judgment, in the lower version of the same way. When determining the version, we need to determine the specific version number, such as
1@TargetApi(9)
2public void doSomeThing() {
3 if(Build.VERSION.SDK_INT >= 9) {
4 // We are using the methods of API 9 normally. If we use the methods of API 11 incorrectly, we will get an error at compile time
5 // Remind us that we are just introducing methods from API 9
6 } else {
7 // TODO uses the old way
8 }
9}
10
11@SuppressLint("NewApi")
12public void doOthers() {
13 if(Build.VERSION.SDK_INT >= 9) {
14 // We are using the methods in API 9 normally. If we use the methods in API 11 incorrectly, we will not report errors
15 // Then running in a lower version causes the risk of a Crash
16 } else {
17 // TODO uses the old way
18 }
19}
Copy the code
8. Launch Mode
Android launchMode understanding and application scenarios