Android Mobile Development Fundamentals Second Edition-After-class Exercises

Chapter 1 Introduction to Android Basics 

Fill in the blanks

1. The Dx tool in the Dalvik virtual machine will convert some class files into __dex____ files

2. If you want to call the color resource file in the XML layout file, you can use _ @color _ __ call

3. The Activity of the Android program entrance is registered in the _ AndroidManifest.xml _ ____ file

4. The tool for viewing application logs in Android is _ _ Log Cat _

True or False

1. The Dalvik virtual machine is a virtual machine designed by Google for the Android platform ( right )
2. The main language of Android applications is Java. ( True)
3. Android adopts a layered structure, which is the application layer, application framework layer, core class library and Linux kernel ( True )
4. The third generation mobile communication technology (3G) includes TD-LTE and FDD-LTE Two systems ( wrong )
5. In Android programs, Log.e() is used to output warning level log information ( wrong )
6. Each Dalvik virtual machine instance is an independent process space, and each process Cannot communicate ( wrong )

Multiple choice questions

1. The Dalvik virtual machine is based on ( C ) architecture
A. stack
B. heap
C. register
D. memory
2. Theme and style resources in Android programs are usually placed in which directory ( C )
A.res/drawable
B .res/layout
C.res/values
​​D.res/assets
3. Among the following statements about the AndroidManifest.xml file, the incorrect one is ( D )
A. It is the configuration file of the entire program
B. The program can be configured in this file Required permissions
C. Components used by the program can be registered in this file
D. This file can set the UI layout
4. Which layer in the Android architecture does the Dalvik virtual machine belong to ( C )
A. Application layer
B. Application Program framework layer
C. Core class library layer
D. Linux kernel layer
5. SMS, contact management, browser, etc. in Android belong to which layer in the Android architecture ( A )
A. Application layer
B. Application framework layer
C. Core class library layer
D. Linux kernel layer

short answer questions

Briefly describe the compilation process of Android source code

Answer: After the Java source files are compiled into class files by the JDK compiler, the Dx tool in the Dalvik virtual machine will convert some class files into dex files, and the dex files will be further optimized into odex files in the Dalvik virtual machine .

Briefly describe the layers contained in the Android architecture and the characteristics of each layer

Answer: The Android system architecture is divided into four layers from high to low, namely, application layer ( Applications), application framework layer (Application Framework), core class libraries (Libraries) and Linux kernel (Linux Kernel) . Each layer The characteristics are as follows:

  1. Application layer: A collection of core applications. All applications installed on the phone belong to this layer.
  2. Application architecture layer: Mainly provides various APIs used when building applications. For example, Activity Manager .
  3. Core class library: mainly includes system libraries and Android operating environment.
  4. Linux kernel: It provides low-level drivers for various hardware of Android devices, such as display drivers.

Chapter 2 Common Android Interface Layouts 

Fill in the blanks

   1. Common layouts in Android are directly or indirectly inherited from the __ ViewGroup _ _ class

   2.TableLayout in Android inherits from _ _ LinearLayout ____

3.TableLayout can control the number of rows in the table    through _ TableRow _ ____

   4.___ Rel a tiveLayout _ __ layout specifies the position of child controls by means of relative positioning

   5. In the R.java file, the android:id attribute will automatically generate the corresponding _ int _ __ type value

True or False

1. ViewGroup is a container for interface controls ( right )
2. If you put 3 buttons with the same properties in FrameLayout, the first added button will be displayed on the screen ( wrong )
3. Android The layout files in are usually placed in the res/layout folder ( right )
4.TableLayout inherits from LinearLayout, so it fully supports the attributes supported by LinearLayout ( right )
5. The android:layout_weight attribute in LinearLayout is used to set controls within the layout weight ( pair )

Multiple choice questions

1. Among the following attributes, the one used to set the direction of LinearLayout is ( A )
   A.orientation
   B.gravity
   C.layout_gravity
   D.padding
2. Among the following options, the one that does not belong to Android layout is ( C )
   A.FrameLayout
   B.LinearLayou
   C .Button
   D.RelativeLayout
3.FrameLayout places the components in its own position ( A )
   A. Upper left corner
   B. Upper right corner
   C. Lower left corner
   D. Lower right corner
4. For XML layout files, the android:layout_width attribute The value cannot be anything ( D )
   A.match_parent
   B.fill_parent
   C.wrap_content
   D.match_content
5. The following description of RelativeLayout is correct ( C )
   A.RelativeLayout represents absolute layout, and you can customize the x and y of the control Location
   B.RelativeLayout represents frame layout, which can realize the function of label switching.
   C.RelativeLayout represents relative layout, in which the positions of controls are relative positions.
   D.RelativeLayout represents table layout, which needs to be used together with TableRow layout.

short answer questions

List common layouts in Android and briefly describe their respective characteristics

   There are five commonly used layouts in Android, namely RelativeLayout (relative layout), LinearLayout (linear layout), FrameLayout (frame layout), TableLayout (table layout), and ConstraintLayout (constraint layout). Their characteristics are as follows :

  1. RelativeLayout (relative layout): This layout specifies the position of the child controls within the layout by means of relative positions.
  2. LinearLayout (linear layout): This layout can specify the horizontal and vertical arrangement of sub-controls in the layout through the android:orientation attribute.
  3. TableLayout (table layout) : Manage controls in the form of rows and columns. It is usually used with TableRow layout. One TableRow represents a row, and the control added in TableRow represents a column.
  4. FrameLayout : This layout will create a blank area on the screen. Each sub-control added to this area occupies one frame. These frames will be superimposed one by one, and the controls added later will be superimposed on the previous control. . By default, all controls in a frame layout are aligned to the upper left corner .
  5. ConstraintLayout (constraint layout): This layout is a newly added layout in Android 2.2. It is suitable for writing interface layout in a visual way. It has relative positioning, centered positioning, tendency, Chain and other properties.

Chapter 3 Common Android Interface Controls 

1. True or False Questions
1. Android control style, each XML attribute corresponds to a Java method. ( Yes  )
2. When the android:checked attribute of the specified RadioButton control is true, it means that the control is unselected. ( wrong  )
3. The AlertDialog dialog box can create objects directly through the new keyword. ( wrong  )
4. Toast is a lightweight information reminder mechanism provided by Android, which is used to prompt users with instant messages. ( Yes  )
5. Data in the ListView control is loaded through the data adapter. ( Yes   )
2. Multiple choice questions
1. A Button control is defined in the XML layout file, and the attribute that determines the text displayed on the Button control is ( B ).
A.android:value
B.android:text
C.android:id
D.android:textvalue
2.Which of the following options is used to set the size of text in a TextView control? ( C )
A.android:textSize="18"
B.android:size="18"
C.android:textSize='18sp'    
D.android:size="18sp"
3.When using the EditText control, if you want to do some prompts when the text content is empty, the attribute you can use is ( D ).
A.android:text
B.android:background
C.android:inputType
D.android:hint
4. In order to let an ImageView control display a picture, the attributes that can be set are ( A ).
A.android:src
B.android:background
C.android:img
D.android:value
5. Among the following statements about the ListView control, the correct one is ( C ).
A. Click events cannot be set for items in the ListView control.
B. The ListView control can display data content without setting a data adapter.
C. When the data exceeds the display range, the ListView automatically has the scrollable feature.
D. There are 100 pieces of data in total. If The ListView control can currently display 10 items, so 100 View controls are generated
6. Which of the following methods is usually used to listen for events when a CheckBox control is selected? ( B )
A.setOnClickListener
B.setOnCheckedChangeListener
C.setOnMenuItemSelectedListener
D.setOnCheckedListener
7. When using the EditText control, the attributes that can set the text box to multi-line display are ( A )
A.android:lines 
C.android:textcolor
B.android:layout_height
D.android:textsize
8. The following description of the AlertDialog dialog box is incorrect ( A ).
A. Use the new keyword to create an instance of the AlertDialog dialog box.
B. The display of the dialog box requires calling the show0 method.
C. The setPositiveButton() method is used to set the OK button.
D. The setNegativeButton() method is used to set the cancel button.

Chapter 4 Program Activity Unit Activity 

1. Fill in the blanks

1. The startup modes of Activity include standard, singleTop, singleTask and ___ singleInstance_ __
2. To start a new Activity and obtain the return data of this Activity, you need to override the startActivityForResult() method.
3. After sending an implicit Intent, Android uses the IntentFilter to match the corresponding component.
4. When adding the <intent-filter> tag to the Activity in the manifest file, the attribute name that must be added is <category android:name="android.intent.category.DEFAULT"/> _____, otherwise the implicit Intent cannot open the Activity.
5. Activity's finish() method is used to close the current Activity. Activity's     finish() method is used to close the current Activity.

Two, judgment question
1. If the Activity does not set the startup mode, the default is standard. ( Yes     )
2. The life cycle methods of Fragment and Activity are consistent. ( wrong     )
3. If you want to close the current Activity, you can call the finish() method provided by the Activity. ( right     )
4. The <intent-filter> tag can only contain one action attribute. ( wrong )
5. By default, the activity's startup mode is standard. ( right     )

3. Multiple choice questions
1. Among the following options, the one that does not belong to the four major components of Android is ( C ).
A. Service                
B. Activity            
C. Handler                
D. Content Provider
2.Among the following descriptions of Activity management methods in Android, the correct one is ( B     ).
A.Android manages Activity in the form of heap        
B.Android manages Activity in the form of stack
C.Android manages Activity in the form of tree        
D.Android manages Activity in the form of linked list
3. Which of the following options is not an Activity life cycle method? ( B     )
A.onCreate()    
B.startActivity()    
C.onStart()            
D.onResume()
4.Which of the following methods is used to start an Activity? ( A )
A.startActivity0()    
B.goToActivity()    
C.startActivityResult()
D. All of the above are
5. Among the following descriptions of Intent, the correct one is ( B     ).
A. Intent cannot realize data sharing between applications
B. Intent can realize switching of interfaces and can also directly transfer data between different components
C. Using explicit Intent does not specify the target component to jump
D. Implicit Intent does not clearly indicate the target component that needs to be activated, so data jumps between components cannot be achieved.

  1. 4. Short answer questions
    1. Briefly describe the Activity life cycle methods and when they are called.
    Answer: Activity has a total of 7 methods. These methods and the timing of calling are as follows:
    1. onCreate(): Called when the Activity is created, usually doing some initialization settings.
    2. onStart(): Called when the Activity is about to be visible.
    3. onResume(): Called when the Activity gets focus.
    4. onPause(): Called when the current activity is covered by other activities or the screen is locked.
    5. onStop(): Called when the Activity is not visible to the user.
    6. onDestroy(): Called when the Activity is destroyed.
    7. onRestart(): Called when the Activity starts from the stopped state again.

    2. Briefly describe the four startup modes of Activity and their characteristics.
      Answer: The four startup modes of Activity are standard, singleTop, singleTask and singleInstance. The characteristics of these modes are as follows:
    1. Standard: Each time an Activity is started, a new instance will be created on the top of the stack.
    2. singleTop: When the started Activity is at the top of the stack, reuse the Activity instance.
    3. singleTask: When the started Activity has an instance in the stack, this Activity instance will be directly reused and all instances of the current Activity will be popped from the stack.
    4. singleInstance: A new task stack will be started to manage the Activity.

    3. Briefly describe the functions of Activity, Intent, and IntentFilter.
    Answer: Activity represents activity, which is one of the four major components of Android. Intent represents intent, and IntentFilter represents filter. Their functions are as follows:
    (1) Activity is a component responsible for interacting with users, and is included in every Android application. Use Activity to display the interface and handle events of some controls on the interface.
    (2) Intent is called intention, which is an important way to interact between components in the program. It can not only specify the action to be performed by the current component, but also transfer data between different components.
    (3) IntentFilter is a filter. When an implicit Intent is sent, the Android system will match it with the filter of each component in the program. The matching attributes include action, data, and category. These three attributes need to match. The corresponding component can only be evoked successfully.

  2. Chapter 5 Data Storage 

  3. 1. True or False Questions
    1. SQLite is a lightweight database that comes with Android and supports basic SQL syntax. ( True )
    2. File storage methods in Android are divided into internal storage methods and external storage methods. ( True )
    3. When using the openFileOutput( method to open the output stream of the application, you only need to specify the file name. ( wrong )
    4. When the AndroidSDK version is lower than 2.3, if the application wants to operate the SD card data, it must add permissions in the manifest file. (right )
    5. The update( method of the SQLiteDatabase class is used to delete data in the database table. ( False )
    6. The transaction operations of the SQLite database satisfy atomicity, consistency, isolation and persistence. ( True )
    2. Multiple choice questions
    1. In the following description of SharedPreferences access files, the wrong one is ( C )
    A. It belongs to the mobile storage solution
    B. SharedPreferences handles key-value pairs
    C. The path to read xml is /sdcard/shared_prefs
    D. The text saving format It is xml
    2. Among the following options, the file operation mode parameter that does not belong to the getSharedPreferences method is ( B ).
    A.Context.MODE_PRIVATE                        
    B.Context.MODE_PUBLIC
    C.Context.MODE_WORLD_READABLE            
    D.Context.MODE_WORLD_WRITEABLE
    3.Among the following methods, ( B    ) is the way SharedPreferences gets its editor.                
    A. getEdit()            
    B. edit()            
    C. setEdit()
    D. getAll
    4.When Android performs query operations on database tables, it will use the ( C     ) method in the SQLiteDatabase class .
    A.insert()            
    B.execSQL()        
    C.query()                
    D.update()
    5. Among the following descriptions of the SQLite database, the incorrect one is ( C     ).
    A. The SqliteOpenHelper class has the function of creating a database and updating the database version.
    B. The SqliteDatabase class is used to operate the database.
    C. Each time the getWritableDatabase() method of the SqliteDatabase class is called, the onCreate() method of the SqliteOpenHelper class will be executed.
    D. When the database version changes, the onUpgrade() method of the SqliteOpenHelper class will be called to update the database.
    6. In the following code to initialize SharedPreferences , the correct one is ( D ).
    A. SharedPreferences sp=new SharedPreferences();
    B. SharedPreferences sp=SharedPreferences.getDefault();
    C. SharedPreferences sp= SharedPreferences.Factory();
    D. SharedPreferences sp=getSharedPreferences();
  4. 3. Short answer questions

  5. 1. Briefly describe the four basic elements of database transactions.
    Answer: The operation of the transaction is relatively strict. It must meet ACID. ACID refers to the abbreviation of the four basic elements for the correct execution of database transactions. These elements include atomicity, consistency, isolation, and durability. Durability, and then explain these four basic elements in detail.
    Atomicity : Indicates that a transaction is an indivisible unit of work, and the operations in the transaction either succeed or fail and roll back.
    Consistency : Indicates that the integrity of the database has not been violated before and after the transaction begins. That is to say, database transactions cannot destroy the integrity of relational data and the consistency of business logic.
    Isolation : Indicates that concurrent transactions are isolated from each other, that is, operations within a transaction must be blocked and will not be affected by other transactions.
    Persistence : means that once a transaction is submitted, the changes to the data made by the transaction will be persisted in the database and will not be rolled back. Even if there is an accident such as a power outage, the data in the database will not be affected.

    2. Briefly describe the way Android data is stored.
    Answer: The five data storage methods provided by the Android platform are file storage, SharedPreferences, SQLite database, ContentProvider and network storage. The characteristics of these storage methods are as follows.
    File storage : Android provides openFileInput() and openFileOutput() methods to read files on the device, and the reading method is exactly the same as the I/O program in Java.
    SharedPreferences : This is a mechanism provided by Android to store some simple configuration information. It uses XML format to store data in the device. Usually, we use SharedPreferences to store various configuration information of some applications, such as user name, password, etc.
    SQLite database : SQLite is a lightweight database that comes with Android. It has fast computing speed, takes up less resources, and supports basic SQL syntax. It is generally used as a storage engine for complex data and can store user information.
    ContentProvider : One of the four major components of Android, mainly used for data exchange between applications, he can share his data with other applications.
    Network storage : It needs to deal with Android network data packets, store data on the server, and store/obtain data information through the storage space provided by the network.

  6. Chapter 6 Content Providers and Content Observers

  7. 1. True or False Questions
    1. Uri mainly consists of three parts, namely scheme, authority and path. ( True )
    2.Content observers are used to observe changes in the data represented by the specified Uri. ( True )
    3.The main function of the content provider is to realize the function of sharing data across programs. ( True )
    4.In Android, when reading the contents of the mobile address book database through the content parser, there is no need to add permission to read the mobile phone address book. ( wrong )
    5.Android's UriMatcher class is used to match Uri. ( True )
    2. Multiple choice questions
    1. If an application wants to access the database of another application, it needs to be implemented through ( C     ).
    A. BroadcastReceiver B.Activity             C.ContentProvider                 D.AIDL
    2. Which of the following methods can obtain an instance object of ContentProvider? ( B )
    A. newContentResolver()                    
    B. getContentResolver()
    C. newInstance()                        
    D. ContentUris. newInstance()
    3. When customizing content observers, the class that needs to be inherited is ( B ).
    A.BaseObserver            
    B. ContentObserver
    C. BasicObserver                
    D. DefalutObserver
    4. When querying mobile phone system text messages, the Uri corresponding to the content provider is ( C ).
    A.Contacts.Photos.CONTENT_URI                
    B.Contacts.People.CONTENT_URI
    C.“content://sms/”                                    
    D. Media.EXTERNAL_CONTENT_URI
    5. The following description of ContentProvider is incorrect ( D ).
    A.ContentProvider is an abstract class and can only be used after inheritance.
    B.ContentProvider can only be run after being registered in the AndroidManifest.xml file.
    C.ContentProvider provides a unified way for other applications to access the database.
    D. None of the above statements are correct
    . 3. Short answer questions
    1. Briefly describe how content providers work.
    answer:Assume that program B needs to operate the data in the database of program A. Generally, program A needs to use ContentProvider
    to expose the data before it can be operated by other programs. Program B operates the data exposed by program A through ContentResolver, and program A will return the operation results to ContentResolver, and then ContentResolver will return the operation results to program B.

    2. Briefly describe how content observers work.
    When using ContentObserver to observe the data of program A, you must first call the notifyChange() method of ContentResolver in the ContentProvider of program A. After calling this method, when program B operates the data in program A, program A will send a data change message to the "Message Center". At this time, program C will observe changes in the data in the "Message Center" and trigger the ContentObserver. onChange() method.

  8. Chapter 7 Broadcasting Mechanism

    1. 1. Fill in the blanks
      1.    BroadcastReceiver  is used to listen for broadcasts from the system or application.
      2. There are two ways to register broadcast receivers, namely     dynamic registration     and     static registration     .
      2. True or False Questions
      1. Broadcast means broadcast, which is a mechanism used to transmit messages between applications. ( True )
      2.When registering a broadcast receiver in the manifest file, you can use the priority attribute in the <intent-filter> tag to set the priority. The larger the attribute value, the higher the priority. ( True )
      3.Ordered broadcast is more efficient than unordered broadcast. ( wrong )
      4. The life cycle of a dynamically registered broadcast receiver depends on the component that registered the broadcast. ( True )
      5. Broadcast receivers in Android must be registered in the manifest file. ( Wrong )
      3. Multiple choice questions
      1. Which statement about the broadcast type among the following options is incorrect ( BC ). (Multiple choices)
      A. The broadcast types in Android are divided into ordered broadcasts and unordered broadcasts
      B. Unordered broadcasts are received according to a certain priority
      C. Unordered broadcasts can be intercepted and the data can be modified          
       
      D. Ordered broadcasts Send according to a certain priority
      2. As a communication method between Android components, what are the scenarios in which the broadcast mechanism is used? ( ABCD ) (Multiple choice)
      A. Message communication within the same component within the same App
      B. Message communication between components in different Apps
      C. Message communication between different components within the same App (single Process)
      D. Message communication between different components with multiple processes in the same App

      4. Short answer questions
      1. Briefly describe the implementation process of the broadcast mechanism.
      Answer: Broadcasting in Android uses the observer pattern, which is a message-based publishing/subscribing event pattern. The broadcast sender and receiver are at the two ends of message publishing and subscription respectively in the observer mode. The implementation process of the broadcast mechanism is as follows:
      1. The broadcast receiver registers in AMS (Activity Manager Service) through the Binder mechanism.
      2. The broadcast sender sends a broadcast to AMS through the Binder mechanism.
      3. AMS finds broadcast receivers that meet the corresponding conditions (IntentFilter/Permission) and sends the broadcast to the corresponding message loop queue.
      4. Obtain the sent broadcast when executing the message loop, then call back the onReceive() method in the broadcast receiver and perform relevant processing in this method.

      2. Briefly describe the difference between ordered broadcast and unordered broadcast.
      Answer: Broadcasting is divided into ordered broadcasting and unordered broadcasting. They have the following differences.
      (1) When sending broadcasts, different methods are used. Ordered broadcast uses sendOrderedBroadcast() to send broadcasts, while unordered broadcast uses sendBroadcast() method to send broadcasts.
      (2) The order of execution of broadcast receivers
              a) The receivers of ordered broadcasts are executed in order.

      Ordered broadcasts are received sequentially according to the priority declared by the broadcast receiver. The broadcast will continue to be delivered after the high-level broadcast receiver logic has been executed. When the priorities are the same, the broadcast receiver that registers first will be executed first.
              b) Out-of-order broadcasts are performed completely asynchronously.
      When an out-of-order broadcast is sent, all broadcast receivers listening to the broadcast will receive the broadcast message, but the order of reception and execution is undefined.
      (3) Interception of broadcasts
      The receiver of an ordered broadcast can intercept the broadcast. If a higher priority broadcast receiver terminates the broadcast, the broadcast will no longer be delivered backwards. Out-of-order broadcasts cannot be intercepted.
      (4) Efficiency
      Ordered broadcast is less efficient than unordered broadcast.

    2. Chapter 8 Services

      1. 1. Fill in the blanks
        1. If you want to stop the service started by the bindService (method), you need to call     the unBindService()         method.
        2. The communication methods of Android services are divided into     local services         and     remote services         . 3. Remote services         realize service communication
        through      AIDL .
        2. True or False Question
        1. Service Runs in a child thread. ( Wrong )
        2. No matter which method is used to start the service, its life cycle is the same. ( Wrong )
        3. When using the service communication method to communicate, you must ensure that the service is bound in mode is turned on, otherwise communication will not be possible. ( Wrong )
        4. A component can only be bound to one service. ( Wrong )
        5. Both remote services and local services run in the same process. ( Wrong )
        3. Multiple choice questions
        1. If When the service is started through bindService, the life cycle of the service is ( C )
        A. onCreate()→onStart()→onBind()→onDestroy()
        B. onCreate()→onBind()→onDestroy()
        C. onCreate()→onBind()→onUnBind()→onDestroy()
        D. onCreate()→onStart()→onBind()→onUnBind()→onDestroy()
        2. Among the following descriptions of services, the wrong one is ( D )
        A. The service has no user-visible interface and cannot interact with the user.
        B. The service can be started through Context.startService()
        . C. The service can be started through Context.bindService().
        D. The service does not need to be configured in the manifest file
        3. The following method description about the service is wrong ( D )
        A.onCreate() indicates the method executed when the service is created for the first time
        . B. The method executed when calling the startService() method to start the service is onStartCommand()
        C. The method executed when calling the bindService() method to start the service is onBind()
        D. The method executed when calling the startService() method to disconnect the service binding is onUnbind()
        4. Short answer questions
        1. Briefly describe the difference between the two startup methods of the service.
        Answer: The startup methods of Service can call the startService() and bindService() methods respectively . The differences between these two startup methods are as follows:
        (1) Different life cycles
                startService(): When using this method to start the Service, the executed life cycle methods are onCreate(), onStartCommand(), and onDestroy() in order.
                bindService(): When using this method to open Service, the executed life cycle methods are: onCreate(), onBind(), onUnbind(), onDestroy().
        (2) The methods of stopping the service are different
                startService(): call the stopSelf() and stopService() methods to stop the service.
                bindService(): Call the unbindService() method to stop the service.
        (3) The association of components is different
                startService(): When a component starts a service through this method, the service is not associated with starting the component. Even if the component that starts the service is destroyed, the service still runs.
                bindService(): When a component starts a service through this method, the service will be bound to the component, and once the component is destroyed, the service will also be destroyed.

        2. Briefly describe the service lifecycle.
        Answer: Use different ways to start services, and their life cycles will be different. The methods to start the service are startService() and bindService() respectively. When the service is started through the startService() method, the executed lifecycle methods are onCreate(), onStartCommand(), and onDestroy() in turn. When the service is started through the bindService() method, the executed life cycle methods are onCreate(), onBind(), onUnbind(), and onDestroy() in order. The specific meanings of its life cycle methods are as follows:
                onCreate (): method executed when the service is created for the first time.
                onStartCommand(): Method executed when the startService() method is called to start the service.
                onBind(): Method executed when the bindService() method is called to start the service.
                onUnbind(): The method executed when calling the unBindService() method to disconnect the service binding.
                onDestory(): The method executed when the service is destroyed.

        Chapter 9 Network Programming

  9. 1. Fill in the blanks
    1. HttpURLConnection inherits from     the URLConnection class.
    2. The built-in browser provided by Android by default uses   the  WebKit        engine.
    3. org. Parsing JSON data in Android. In the json package, the two most important classes are     JSONObject         and JSONArray .
    2. True or False Questions
    1. HttpURLConnection is used to send HTTP requests and get HTTP responses. ( True )
    2.The WebView control in Android is specially used for browsing web pages, and its usage method is the same as other controls. ( True )
    3.To access the network in Android, it must be in AndroidManifest. Register network access permissions in xml. ( True )
    4.HttpURLConnection is an abstract class and cannot be directly instantiated. It needs to be obtained using the openConnection0 method of the URL. ( right )
    5.When using HttpURLConnection for HTTP network communication, the GET request method can only send data within 1024 bytes ( correct )
    3. Multiple choice questions
    1. Android's methods of implementing network communication for HTTP mainly include ( ABCD   ). (Multiple choices)
    A. Use HttpURLConnection to implement                
    B. Use ServiceConnection to implement
    C. Use HttpClient to implement                        
    D. Use HttpConnection to implement

    2. The input/output stream operations of HttpURLConnection in Android are uniformly encapsulated (  ABD   ). (Multiple choice)
    A. HttpGet                    
    B.        
        
    HttpPost C. HttpRequest            
    D. HttpResponse
    4. Short answer questions
    Briefly describe the steps of using HttpURLConnection to access the network.

  10. Answer: The steps to use HttpURLConnection to access the network are as follows:
    (1) Create a URL object.
    (2) Call the openConnection() method of the URL object to obtain the HttpURLConnection object.
    (3) Call the setRequestMethod() method to set the http request method.
    (4) Set the connection timeout through the setConnectTimeout() method.
    (5) Call the getInputStream() method to obtain the input stream returned by the server.
    (6) Finally, call the disconnect() method to close the http connection.

  11. Chapter 10 Graphics and Image Processing

  12. 1. Judgment question
    1. The Paint class represents a brush, which is mainly used to describe the color and style of graphics. ( Yes )
    2. The Matrix class provided by Android can be combined with other APIs to transform graphics, such as rotation, scaling, and tilting. ( yes )
    3. The decodeFile(method of Bitmap class is used to parse Bitmap objects from files. ( Correct )
    2. Multiple choice questions
    1. Among the following descriptions of Android animations, the correct one is ( ABC     ). (Multiple choice)
    A. Animations in Android are usually It is divided into two types: frame-by-frame animation and tweening animation.
    B. Frame-by-frame animation is an animation effect formed by sequentially playing a set of predefined static images.
    C. Tween animation is to produce animation by continuously changing the images of objects in the scene. Effect

    D. When implementing tweening animation, you only need to define the key frames of the beginning and end of the animation, and other transitions will be automatically calculated and completed by the system 2.
    What tweening animations does Android provide? ( ABCD     )
    A. Transparency Gradient Animation (AlphaAnimation)        
    B .Rotate Animation (RotateAnimation)
    C. Scale Animation (ScaleAnimation)                
    D. Translate Animation (TranslateAnimation)

    3. The most commonly used classes when Android draws images include ( ABCD     ).
    A. Bitmap class        
    B. BitmapFactory class        
    C. Paint class                
    D. Canvas class

    4. In Android, use the ( B     ) method in the Canvas class to draw ellipses.
    A. drawRect()        
    B. drawOval()        
    C. drawCircle()            
    D. drawLine()
    5.The following description about the Canvas class is wrong ( C ).
    A. The Canvas class represents the canvas.
    B. The Canvas class can draw a variety of graphics.
    C. The Canvas class has the same function as the Paint class.
    D. The drawRect() method of the Canvas class is used to draw rectangles.
  13. Chapter 11 Multimedia Application Development

  14. 1. True or False Questions
    1. The SurfaceView control inherits from View, which is a control that displays images. ( Yes     )
    2. SurfaceView control has double buffering technology. ( Yes     )
    3. When using the MediaPlayer class to play videos, the SurfaceView control must be updated in the child thread when displaying the video. (wrong)
    4.You can use the SoundPool class in Android to play multiple audio files at the same time. ( Yes     )
    5. When using the VideoView control to play videos, you need to use the setVideoPalh() method to set the playback video path. ( Yes     )
    2. Multiple choice questions
    1. In the following description about multimedia application development, the correct one is ( ABC     ). (Multiple choices)
    A. You can use the MediaPlayer class or the SoundPool class to play audio.
    B. The MediaPlayer class can only play one audio at a time, which is suitable for playing long music or background music.
    C. The SoundPool class can be used to play multiple short audios at the same time. It is suitable for It is used to play button sound or message prompt sound

    D.SoundPool class is used together with SurfaceView control, and can also play video
    2. setAudioStreamType in the MediaPlayer class (the audio types supported by the method include (     ABC ). (Multiple choices)
    A.Music                    
    B.Bell                    
    C.Alarm clock     
               
    D.Tone
    3. The following description of the MeidiaPlayer class is incorrect ( D     ).
    A. The MediaPlayer class is used to play audio and video.
    B. The MadiaPlayer class provides a very comprehensive control method for audio files.
    C. The MadiaPlayer class calls the underlying audio driver to play audio.
    D. The MadiaPlayer class can only play audio but not video.

Guess you like

Origin blog.csdn.net/Ipkiss_Yongheng/article/details/125112217