Android Application Architecture
Src/java Original Code Storage directory
gen/Automatic Directory Generation
The Gen directory holds all files that are automatically generated by the Android development tool. The most important thing in the directory is the R.java file. This file is automatically generated by the Android development tool. The Android development tool automatically modifies the R.java file according to the XML interface files, icons, and constants that you put into the Res directory. Because R.java files are generated automatically by development tools, we should avoid manually modifying R.java. R.java in the application of the role of the dictionary, it contains the interface, icons, constants and other resources of the ID, through the R.java, the application can easily find the corresponding resources. In addition, the compiler will check whether the resources in the R.java list are used, and the unused resources will not be compiled into the software, which can reduce the space used in the mobile phone.
res/resource (Resource) directory
A variety of resources, such as XML interface files, images, or data, used to store applications.
Androidmanifest.xml Feature manifest file
Lists the features provided by the application, in which you can specify which services the application uses (such as telephony, Internet services, SMS, GPS services, and so on).
When you add a new activity, you also need to configure it in this file, which can only be invoked when it is configured.
Default.properties Project environment information, generally do not need to modify this file
Intent: The activity is initiated by startactivity () when the activity is found with the same Intent limit as the set.
Telephone Broadcasting Device:
To add a Telephony service permission in Androidmanifest.xml:
The code is as follows |
Copy Code |
<uses-permission android:name= "Android.permission.CALL_PHONE"/>
|
2) Interface layout
The code is as follows |
Copy Code |
LinearLayout (linear layout), Absolutelayout (absolute layout), relativelayout (relative layout), tablelayout (table layout), Framelayout (frame layout)
|
3) Activity:
Increase the Click event for the button to add code to handle the event in this event
In Android development, there's a lot of internal classes for efficiency reasons, and this is where it often happens.
Adds a Click event to the button and handles the program in the event.
The code is as follows |
Copy Code |
Intent.setaction ("Android.intent.action.CALL"); Intent.addcategory ("Android.intent.category.DEFAULT"); Intent.setdata (Uri.parse ("Tel:" + strmobile)); StartActivity (Intent)//method will automatically add categories for intent: Android.intent.category.DEFAULT
Or Button.setonclicklistener (New View.onclicklistener () { public void OnClick (View v) { EditText EditText = (edittext) Findviewbyid (r.id.mobile); Intent Intent = new Intent (Intent.action_call, Uri.parse ("Tel:" + edittext.gettext ())); DialerAction.this.startActivity (Intent); }
|
SMS Transmitter:
code is as follows |
copy code |
Smsmanager manager = Smsmanager.getdefault (); arraylist<string> texts = Manager.dividemessage (comtent); for (String text:texts) { Manager.sendtextmessage (number, NULL, text, NULL, NULL),//4 and 5 parameters are sent SMS status, whether the other party received the message status; } Toast.maketext (Getapplicationcontext (), R.string.success,toast.length_long). Show (); Toast.maketext dialog (Mainactivity.this, Resid, duration);//inner class access external class; **************************************************************** Findviewbyid (R.id.button);//Find display control based on ID; View.onclicklistener () { @Override public void OnClick (View arg0) { ARG0 is the object that was clicked } } @+id/button: Within the ID class of the R file, add a constant with the ID button, using the value of the constant as the ID value of the control; @android: Access to the R file under the Android package; @id/label: Indicates access to a file with ID label; (relative layout) Unit test: |
Inheriting classes: Androidtestcase
The code is as follows |
Copy Code |
<instrumentation Android:name= "Android.test.InstrumentationTestRunner" Android:targetpackage= "Com.hellokity"/> <application android:icon= "@drawable/ic_launcher" Android:label= "@string/app_name" > <uses-library android:name= "Android.test.runner"/> </application> actual = function (); Assert.assertequals (3,actual), judge whether the actual is 3; |
Knot
--Don't forget to add service permissions in Androidmanifest.xml when using system services
--SMS service here, using the Smsmanager class, to operate.
--When sending text messages to determine whether more than 70 words
Don't forget to show () when--toast is in use. Otherwise it will not be displayed.