Android is an important part of Google's enterprise strategy. This strategy has greatly improved Google's market in the Chinese mobile industry and greatly promoted the competitiveness of the entire mobile industry, the following describes the content of the Android mobile phone program.
In this way, an Application is started when the program is started, and then the corresponding Activity is loaded during the Application running process, and the Activity requires an interface. But this is not the case with Instrumentation. You can understand Instrumentation as a startup capability without a graphical interface.
Tool class used to monitor other classes (declared using Target Package. Any class to be Instrumentation must inherit android. app. Instrumentation. The following is an explanation of this class:
- private SensorEventListener listener = new SensorEventListener(){
- public static volatile float direction = (float) 0;
- public static volatile float inclination;
- public static volatile float rollingZ = (float)0;
-
- public static volatile float kFilteringFactor = (float)0.05;
- public static float aboveOrBelow = (float)0;
-
- public void onAccuracyChanged(Sensor arg0, int arg1){}
-
- public void onSensorChanged(SensorEvent evt)
- {
- float vals[] = evt.values;
-
- if(evt.sensor.getType() == Sensor.TYPE_ORIENTATION)
- {
- float rawDirection = vals[0];
-
- direction =(float) ((rawDirection * kFilteringFactor) +
- (direction * (1.0 - kFilteringFactor)));
-
- inclination =
- (float) ((vals[2] * kFilteringFactor) +
- (inclination * (1.0 - kFilteringFactor)));
-
-
- if(aboveOrBelow > 0)
- inclinationinclination = inclination * -1;
-
- if(evt.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
- {
- aboveOrBelow =
- (float) ((vals[2] * kFilteringFactor) +
- (aboveOrBelow * (1.0 - kFilteringFactor)));
- }
- }
- }
- };
For unit testing, we need to carefully understand the android. test. InstrumentationTestRunner class. This is the main portal for unit testing of Android mobile phones. It is equivalent to the role of TestRunner in JUnit. So how to load it, first add a line of statements about Instrumentation in the manifest file. For example, the manifest in the test in Android Api Demos is written like this (I filtered out all comments ):
After editing the manifest file, you can package it (build, use Eclipse ADT, or manually run the aapt command) and install it on the Virtual Machine (use the adb install command ). Then you can use the command line method to load your unit test. To load an Instrumentation file in the Shell of the Android mobile phone program, run the following command:
Of course, you can also use the adb shell to first enter the android command line mode, and then directly write am instrument-w XXXXXXX. The following describes how to load a group of unit tests as needed.