[Android] Final project fill in the blanks and code questions

Experiment two

1. The purpose of the experiment
1. Master the usage of explicit Intent
2. Master the usage of implicit Intent
3. Be familiar with more implicit Intent usage
4. Master the method of using Intent to transfer objects

The three basic components of Android-Activity, Service, and BroadcastReceiver, are all activated through the Intent mechanism, and different types of components have different ways of delivering Intent.
(1) startActivity(Intent)/startActivityForResult(Intent): to start an Activity;
(2) startService(Intent)/bindService(Intent): to start a Service;
(3) sendBroadcast: send broadcast to the specified BroadcastReceiver.

Item one explicit Intent usage

Explicit Intent: Specify the target component to be started by the component name, such as startActivity(new Intent(A.this,B.class)); Only one component is started each time.
Follow the steps shown in the figure below to complete:

Insert picture description here

Reference Code:

Insert picture description here
Insert picture description here

Note: Main2Activity.class needs to be created above (this can be achieved by creating an activity). The layout file can be completed by itself.

Project two implicit intent usage

Implicit Intent: do not specify the component name, but specify the Action, Data or Category of the Intent. When we start the component, we will match the Intent-filter of the AndroidManifest.xml related components, and match the groups that satisfy the attributes one by one, when more than one is satisfied When, a dialog box will pop up to let us choose which one to start.
Follow the diagram below to complete:

Insert picture description here

Reference Code:

Insert picture description here


Insert picture description here


Insert picture description here

Project three Intent transfer data

Refer to PPT to realize two ways to transfer data.
The first step is to create a project and create two more activities, similar to the following figure:

Insert picture description here

The second step, layout file design and implementation, here is a reference.
The main layout file is as follows.

Insert picture description here

The other two layout files do not need to write code separately.
The third step is to complete the logic program. (Refer to the code, you can check relevant information to complete)

Insert picture description here
Insert picture description here
Insert picture description here

Project four Intent transfer object

这里只实现一种方式,参照PPT。下面的程序只是参照,具体可查资料完成。

The first step is to create a project

Insert picture description here

The second step, layout file design

Insert picture description here

The third step is to realize the logic program

Insert picture description here
Insert picture description here

Project 5 Intent data

You can refer to the
first step of the textbook or ppt to create a project

Insert picture description here

The second step, the layout is realized

Insert picture description here
Insert picture description here

The third step, the program is realized

Insert picture description here

Experiment 10 Use mobile phone multimedia to implement 2

1. The purpose of the experiment

1. Master the call of the camera;
2. Master the playback of multimedia files (audio, video).

2. Experimental steps

Item 1. Play audio (SD card exists)

Follow the steps shown in the figure:

Insert picture description here
Insert picture description here


Insert picture description here
Insert picture description here
Insert picture description here

Project two, play video (SD card exists)

Follow the steps shown in the figure:

Insert picture description here


Insert picture description here
Insert picture description here
Insert picture description here

Project three, play local video (VideoView)

See P259-260 for specific implementation

Experiment 11

1. The purpose of the experiment
1. To master the usage of WebView;
2. To master the usage of HttpURLConnection;

1. Basic usage of using WebView

The first step, layout files:
In the activity_layout.xmlAdd WebView control.
The second step is to modify the main program:

Insert picture description here

The third step is to add a permission statement (complete with reference to the textbook).

<uses-permission android:name="android.permission.INTERNET" />

2. WebView instance

Refer to the code below to complete, or see the textbook.

Insert picture description here
Insert picture description here


Insert picture description here

Finally, modify the configuration file.

3. Usage of using HttpURLConnection

The first step, the layout file:

Insert picture description here

The second step is to modify the main program:

Insert picture description here


Insert picture description here


Insert picture description here

The third step: increase the permission statement.

Experiment four database implementation one

1. The purpose of the experiment

1. Master the file storage method
2. Master the SharedPreferences storage method

2. Experimental steps

Project one file storage example 1

The first step: modify the layout file in the created project, where the file name is (not the same): activity_main.xml, see the figure below.

Insert picture description here

Step 2: Store the data in a file.
First, write a save() method in the main program;

Insert picture description here

Then, write the following code in onCreate() and onDestroy():

Insert picture description here

The third step: read data from the file.
First, write a method load() which is taken out in the main program;

Insert picture description here

Finally, add the following code in onCreate().

Insert picture description here

Project two file storage example 2

UI interface design reference is as follows:

Insert picture description here

The program code reference is as follows (part of the code, see the textbook for details):

Insert picture description here
Insert picture description here

Project three SharedPreferences storage instance 1

Steps: The
first step is to modify the layout file of the project, where the file name is activity_main.xml;

Insert picture description here

The second step is to save the data and write the following code in the main program onCreate();

Insert picture description here

The third step is to read the data and write the following code in the main program onCreate();

Insert picture description here

Use Logcat to get data results.

Insert picture description here

Project four SharedPreferences storage instance 2

UI interface design reference is as follows:

Insert picture description here

The program code reference is as follows (part of the code, see the textbook for details)

Insert picture description here

Experiment 7 Database Implementation 2

1. The purpose of the experiment

1. Master the methods of Sqlite to create and upgrade databases
2. Master the CRUD implementation methods of Sqlite to implement databases

2. Experimental steps

1. Create and upgrade the database

Note: Create a new project.
Step 1: Create a database and create a new MydatabaseHelper class as shown in the figure below.

Insert picture description here

Step 2: Modify the layout file

Insert picture description here

Step 3: Write the following code in the main program

Insert picture description here

After running, you can find the database in the corresponding location and save it separately. Software that can open *.db files for viewing (download and install by yourself).

Insert picture description here

The steps to upgrade the database are the same as above. The specific procedure is shown in the series of diagrams below.

Insert picture description here
Insert picture description here

2. Implement CRUD

Note: Create a new project.
Steps: The
first step is to modify the layout file of the project, where the file name is activity_main.xml;

Insert picture description here

The second step is to add data and write the following code in the main program;

Insert picture description here

The third step is to update the data, write the following code in the main program;

Insert picture description here

The fourth step is to delete the data and write the following code in the main program;

Insert picture description here

The fifth step is to query the data and write the following code in the main program.

Insert picture description here