In-depth analysis of components of the Android mobile phone program

Source: Internet
Author: User

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:

 
 
  1. private SensorEventListener listener = new SensorEventListener(){  
  2.    public static volatile float direction = (float) 0;  
  3.    public static volatile float inclination;  
  4.    public static volatile float rollingZ = (float)0;  
  5.  
  6.    public static volatile float kFilteringFactor = (float)0.05;  
  7.    public static float aboveOrBelow = (float)0;  
  8.  
  9.    public void onAccuracyChanged(Sensor arg0, int arg1){}  
  10.  
  11.    public void onSensorChanged(SensorEvent evt)  
  12.    {  
  13.       float vals[] = evt.values;  
  14.         
  15.       if(evt.sensor.getType() == Sensor.TYPE_ORIENTATION)  
  16.       {  
  17.          float rawDirection = vals[0];  
  18.  
  19.          direction =(float) ((rawDirection * kFilteringFactor) +   
  20.             (direction * (1.0 - kFilteringFactor)));  
  21.  
  22.           inclination =   
  23.             (float) ((vals[2] * kFilteringFactor) +   
  24.             (inclination * (1.0 - kFilteringFactor)));  
  25.  
  26.                   
  27.           if(aboveOrBelow > 0)  
  28.              inclinationinclination = inclination * -1;  
  29.             
  30.          if(evt.sensor.getType() == Sensor.TYPE_ACCELEROMETER)  
  31.          {  
  32.             aboveOrBelow =  
  33.                (float) ((vals[2] * kFilteringFactor) +   
  34.                (aboveOrBelow * (1.0 - kFilteringFactor)));  
  35.          }  
  36.       }  
  37.    }  
  38. }; 

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.