Jiangxi University of Science and Technology Android Final Review Questions 2019

1. Multiple choice questions

1. When using RadioButton in android, the components needed to achieve mutually exclusive selection are ()

A、ButtonGroup

B、RadioButtons

C、CheckBox

D 、 RadioGroup

2. Which statement about Handler is correct ()

A. It implements a mechanism for communication between different threads

B. It avoids new threads operating UI components

C. It uses a stack to organize tasks

D. It can belong to a new thread

3. Which of the following can be used as the prompt message of the EditText edit box?

A、android:inputType

B、android:text

C、android:digits

D、android:hint

4. Exit Activity to save some resources and state operations, which function can be performed in the life cycle. ()

A、onPause() 

B、onCreate() 

C、onResume() 

D、onStart()

5. What is the function of the assets directory under the Android project? () 

A. Place the applied image resource Res/drawable.

B. Mainly place some file resources, these files will be packaged into the apk intact 

C. Place string, color, array and other constant data res/values 

D. Place some layout files corresponding to the UI, which are all xml files res/layout

6. The role of Intent is ()  

A. Intent is the link that connects the four major components, can switch between interfaces, and can contain actions and action data. 

B. It is a long life cycle. A program without a user interface can keep the application running in the background without disappearing due to switching pages.

C. Realize data sharing between applications.

D. Deal with the overall work of an application.

7. Which of the following is a unique attribute in AbsoluteLayout? ()

A、android:layout_height 

 B、android:layout_x  

C、android:layout_above

  D、android:layout_toRightOf

8. The commonly used database in mobile phone development is ()

A、sqlLite   

B、Oracle    

C、Sql Server 

D 、 Db23

9. What is incorrect about BroadcastReceiver ()

A. It is used to receive broadcast Intent.

B. A broadcast Intent can only be received by a BroadcastReceiver subscribed to this broadcast.

C. For ordered broadcasting, the system will execute the receivers one by one according to the priority declared by the receivers.

D. The priority declared by the receiver is declared in the android:priority attribute of <intent-filter>. The larger the value, the higher the priority.

10. When using MediaPlayer to play mp3 files saved on sdcard ()

A. You need to use the MediaPlayer.create method to create a MediaPlayer.

B. Just use newMediaPlayer directly.

C. Need to call the setDataSource method to set the file source.

D. Call the start method directly without setting the file source.

11. When reading shared storage data in multiple applications, which object method is the query method that needs to be used? ()

A 、 ContentResolver   

B、ContentProvider

C Cursor               

D、SQLiteHelper

12. How many levels are there in Log information in the memory monitoring tool DDMS? ()

A、3       

B、4     

C、5       

D、6

13. Regarding the optimization method of custom Adapter, we usually use three methods, the following can not be used ()

A. Reuse layout view objects

B. Asynchronous loading of pictures 

C, component reuse  

D. Create an internal class

14. The component that can automatically complete the input is ()

A、TextView   

B、EditText 

C、ImageView    

D、AutoCompleteTextView

15. The component representing the drop-down list is ()

A、Gallery    

B、Spinner    

C、GridView  

D、ListView

16. You need to find a TextView component whose id is bookName in Activity. Which of the following statements is correct? () 

A、TextView tv = this.findViewById(R.id.bookName); 

B、TextView tv = (TextView)this.findViewById(R.id.code); 

C、TextView tv = (TextView)this.findViewById(R.id.bookName); 

D、TextView tv = (TextView)this.findViewById(R.string.bookName);

17. The Android SDK provides a tool for processing pictures to solve the problem of adapting to different screen resolutions. ()

A、Draw7-patch  

B、Draw8-patch

C、Draw9-patch  

D、Draw10-patch

18. The following statement is wrong ()

A. Button is a common button component, in addition to other button components.

B. TextView is a component that displays text, and TextView is the parent class of EditText.

C. EditText is a component for editing text, you can use EditText to input specific characters.

D. ImageView is a component that displays pictures, which can be set to display partial pictures.

19. What does the Android API provide to developers in the form of Content Provider so that they can perform a series of operations on the address book? ()

A. File browser  

B. Database file  

C, system address book  

D, data sheet

20. Android API provides a series of classes to implement or operate Content Provider related functions, the one not mentioned below is ()

A、Content Provider  

B、Content Resolver  

C、ContentValues  

D 、 Content Changer

21. What construction method is usually used to construct ArrayAdapter? ()

A.ArrayAdapter<T>(Context context,int textViewResourceId)

B.ArrayAdapter<T>(Context context,T[] objects)

C.ArrayAdapter<T>(Context context,int textViewResourceId,T[] objects)

D.ArrayAdapter<T>(int textViewResourceId,T[] objects)

22. The following statement is wrong ()

A. Button is a common button component, in addition to other button components.

B. TextView is a component that displays text, and TextView is the parent class of EditText.

C. EditText is a component for editing text, you can use EditText to input specific characters.

D. ImageView is a component that displays pictures, which can be set to display partial pictures.

23. The method of handling the menu item click event does not include ()

A. Use onOptionsItemSelected(MenuItem item) to respond.

B. Use onMenuItemSelected(int featureId, MenuItem item) to respond.

C. Use onMenuItemClick(MenuItem item) to respond.

D. Use onCreateOptionsMenu (Menu menu) to respond.

Two, short answer questions

1. List the five process priorities in the Android system and give a detailed introduction.

Answer: foreground process>visible process>service process>background process>empty process.

(1) The foreground process indicates that the user is interacting with the process.

(2) Visible process refers to a process in which part of the program interface can be seen by the user, but is not interacting with the user in the foreground, and does not respond to interface events.

(3) A service process refers to a process that includes a started service. It has no user interface and runs in the background for a long time.

(4) Background process refers to an Activity process that does not contain any started services and has no user-visible activity.

(5) Empty process, a process that does not hold any active components.

2. Introduction Android system has four important components.

Answer: The four basic components of the Android system are Activity, Service, Broadcase Receiver and Content Provider.  

(1) Activity is the presentation layer of the Android program, displaying a visual user interface, and receiving interface events generated by interaction with the user, which is used to remind the user that the program has been started normally.

(2) Service is generally used for applications that have no user interface but need to run in the background for a long time.

( 3 ) Broadcase Receiver is a component used to receive and respond to broadcast messages. 

( 4 ) Content Provider is a mechanism for sharing data provided by the Android system, and applications can access private data of other applications through Content Provider.  

3. In the Android life cycle process, which 4 states does Activity generally exhibit?

Answer: (1) Active state, the state that can be seen by the user and interacted with the user.

( 2 ) In the paused state, the Activity is not at the top of the user interface, it has lost its focus, and cannot interact with the user.

( 3 ) In the stopped state, the Activity cannot be seen by the user at all on the interface, and the current data and UI state are saved .

( 4 ) In dead state, Activity is destroyed by the system .

4. Definition and purpose of Intent in Android system? What are the two ways for Intent to start Activity?

Definition: Provide interaction capabilities for other components, and transfer data and actions of one component to another.

Purpose: 1) Start Activity and Service

           2 ) Publish broadcast news

Start method: Explicit call , specify the Class class that calls the Activity ; implicit call , no need to specify which Activity to start, the choice is similarly determined by the Android system and the end user.

5. What are the two ways to use Service? Describe the service life cycle.

Start by Context.startService()

Start by Context.bindService()

6. What is the core part of the SQLite database architecture? 

Answer: Virtual machine/virtual database engine. It completes all operations related to data operations and is an intermediate unit for information exchange between customers and storage.

7. What kind of interface mechanism is ContentProvider between applications? A new data provider can be created by inheriting the ContentProvider class. Please briefly describe the process.

Answer: ContentProvider provides a unified interface for data sharing between different software.

1) Define the URI, the uniform resource identifier, which is used to uniquely identify the Content Provider and its data. 

2 ) Set the MIME data type, the function is to specify a certain extension file to open with a certain application.

3 ) Implement the methods of initialization, query, insert, update, delete, and return.

onCreate(): initialize provider query(): query data

insert(): insert data into the provider update(): update the data of the provider

delete(): delete the data in the provider getType(): return the MIME type of the data in the provider

8. What is the medium for information exchange between the system and users? What information is converted?

Answer: User interface. Realize the conversion between the internal form of information and the form acceptable to humans.

9. What interface is used in Android to define the window of remote service? What is the extension of the service interface file?

Answer: AIDL .aidl

10. Briefly describe the characteristics and usage of the three menus of the Android system.

(1) Option menu: It can be divided into icon menu and extended menu. The icon menu has a maximum of six sub-items. It supports displaying icons, but does not support single-select boxes and check boxes; and when there are more than six sub-items, use The extended menu, the sub-items of the extended menu are arranged vertically, support single selection boxes and check boxes, and do not support displaying icons. When you start the option menu for the first time, you only need to call the onCreateMenu function once.

(2) Submenu: It can display more detailed information, add submenu through the addSubMenu function, but does not support nesting.

(3) Shortcut menu: After clicking on an interface element for more than 2 seconds, the shortcut menu of the interface element will be launched. The onCreateMenu function is called once every time it starts.

Three, programming questions

1. Write an Android program, use AsyncTask to obtain the html code of the web page, and use TextView to display it.

public class MainActivity extends Activity {  
    // 定义组件  
    private EditText edtURL;  
    private TextView edtHTTP;  
    private Button btnRequest;  
    private String strURL;// 用于存储网站地址  
    private MyTask myTask;  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_main);  
        // 初始化组件  
        edtURL = (EditText) findViewById(R.id.edturl);  
        edtHTTP = (EditText) findViewById(R.id.edthttp);  
        btnRequest = (Button) findViewById(R.id.requesthtml);  
        // 监听获取html代码的按钮  
        btnRequest.setOnClickListener(new View.OnClickListener() {  
            @Override  
            public void onClick(View v) {  
                if (!(strURL = edtURL.getText().toString()).equals("")) {  
                    //实例myTask对象  
                    myTask = new MyTask(edtHTTP);  
                    myTask.execute(strURL);  
                }  
            }  
        });  
    }  
  
}  

public class MyTask extends AsyncTask<String, integer, StringBuffer> {  
    private TextView edtHTTP;// 用于显示HTML代码  
    private StringBuffer sbHTML;// 用于储存HTML代码  
    public MyTask(TextView edtHTTP) {  
        this.edtHTTP = edtHTTP;  
        sbHTML = new StringBuffer();  
    }  
  
    /** 
     * doInBackground方法内部执行后台任务,不可在此方法内修改UI 
     */  
    @Override  
    protected StringBuffer doInBackground(String... params) {  
        // 初始化HTTP的客户端  
        HttpClient hc = new DefaultHttpClient();  
        // 实例化HttpGet对象  
        HttpGet hg = new HttpGet(params[0]);  
        try {  
            // 让HTTP客户端已Get的方式请求数据,并把所得的数据赋值给HttpResponse的对象  
            HttpResponse hr = hc.execute(hg);  
            // 使用缓存的方式读取所返回的数据  
            BufferedReader br = new BufferedReader(new InputStreamReader(hr  
                    .getEntity().getContent()));  
            // 读取网页所返回的HTML代码  
            String line = "";  
            sbHTML = new StringBuffer();  
            while ((line = br.readLine()) != null) {  
                sbHTML.append(line);  
            }  
            return sbHTML;  
        } catch (IOException e) {  
  
            edtHTTP.setText("获取网页HTML代码出错!!!");  
        }  
        return null;  
    }  
  
    /** 
     * onPostExecute方法用于在执行完后台任务后更新UI,显示结果 
     */  
    @Override  
    protected void onPostExecute(StringBuffer result) {  
        // 判断是否为null,若不为null,则在页面显示HTML代码  
        if (result != null) {  
            edtHTTP.setText(result);  
        }  
        super.onPostExecute(result);  
    }  
}  

2. Write a program, enter two integer values, and click the sum button to display the sum of the two numbers.

MainActivity.java
public class MainActivity extends AppCompatActivity {
    EditText one,two;
    Button add;
    TextView show;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        one = findViewById(R.id.one);
        two = findViewById(R.id.two);
        add = findViewById(R.id.add);
        show = findViewById(R.id.show);
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String first = one.getText().toString();
                String second = two.getText().toString();
                try {
                    int add = Integer.parseInt(first) + Integer.parseInt(second);
                    show.setText("两数之和:"+ add);
                } catch (Exception e) {
                    show.setText("请输入数字!");
                }
            }
        });
    }
}

<LinearLayout>
    <EditText
        android:id="@+id/one"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <EditText
        android:id="@+id/two"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
       />
    <Button
        android:id="@+id/add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="add" 
       />
    <TextView
        android:id="@+id/show"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>

3. Programming the main interface with "login button", click on the "login" button to open the second activity, the second activity displays the user name and password entered in the main interface, and define the return key to pass the user name and password back to the homepage In the Acivity of the surface.

MainActivity.java
public class MainActivity extends AppCompatActivity {
    EditText name,password;
    Button register;
    TextView show;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        name = findViewById(R.id.name);
        password = findViewById(R.id.password);
        register = findViewById(R.id.register);
        show = findViewById(R.id.show);

        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String message = name.getText().toString() + "\n" + password.getText().toString();

                Intent intent = new Intent(MainActivity.this, Second_Activity.class);
                intent.putExtra("message", message);
                startActivityForResult(intent,1);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode==1 && resultCode==2) {
            String result=data.getStringExtra("data");
            show.setText(result);
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}


Second_Activity.java
public class Second_Activity extends Activity{
    Button back;
    TextView message;
    String send;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second_view);

        back = findViewById(R.id.back);
        message = findViewById(R.id.message);

        Intent intent = getIntent();
        String result = intent.getStringExtra("message");
        send = result;
        message.setText(result);

        back.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent data = new Intent();
                data.putExtra("data", send);
                setResult(2,data);
                finish();
            }
        });
    }
}
<LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="用户名:" />
        <EditText
            android:id="@+id/name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密码:" />
        <EditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword" />
    </LinearLayout>
    <Button
        android:id="@+id/register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="登陆" />
    <TextView
        android:id="@+id/show"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout >
    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <Button
        android:id="@+id/back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="back" />
</LinearLayout>

 

Guess you like

Origin blog.csdn.net/qq_38452951/article/details/90179139