. NET developers learn about Android Development Week

Source: Internet
Author: User

During the spring festival, relatively busy, there is nothing to do at work. Use this week's time to learn a little bit about mobile development. Mainly for Android, in fact I am more interested in iOS (because I use the iphone), suffering from the temporary lack of an Apple computer, can only put it to learn later. I do not use mobile development for the time being, I have been doing the. NET application before. Take a look at a. NET developer's mind and learn a little bit about the Android development learning experience. The beginner's nonsense, the master please smile and past.

    1. Development environment Construction

Download the JDK installation first. For Android SDK and Eclipse, you can download it directly to the Android website (http://developer.android.com/sdk/index.html#download), which has already packaged eclipse , downloaded to be used directly, without the need to configure the Android SDK.

For the simulator, I recommend a bluestack, very good and powerful, much faster than the AVD on eclipse. The only drawback is that the screen is large, as if the size of the screen can not be adjusted.

2. Android Project structure

For the entire Android project, we typically need to focus on two directories and one file that are commonly used.

    • SRC directory, all Java code is in this directory.
    • Res directory, where all the resource files are in this directory.
    • Androidmanifest.xml files, System configuration information, very important one file. The authorization of some functions and pages in the system is defined here. Sometimes some features or pages do not make a successful call, you can first check whether the file is authorized.

3. Activity

The most basic task object in Android, I simply understand it as a. NET developed form or page. There can be multiple view on an activity, and all controls (widgets) are inherited from view. There are two aspects to the activity layout, one is to use the layout file, the code to load the corresponding layout file, the equivalent of a good control of the form, and the other is the dynamic code to implement the layout, like in. NET dynamically generated pages.

4. Intent

Communication between the two activity passes through the intent. I interpret it as a request + response object similar to ASP. Intent can pass one or more data, and the delivery of multiple data is generally packaged into a bundle. Intent uses the Putextras method to load the passed information. The subform can be used getintent to get the intent passed over.

    • Open a subform that does not need a return value directly with startactivity (intent).
    • Open a subform with Startactivityforresult to return a value. The subform uses Setresult (RESULT_OK, intent) to set the return value, and the parent form needs to overload the Onactivityresult method to get the return information.
    • With intent, you can invoke system functions such as mail, SMS, phone, contacts, etc. Calling a system feature or form requires a URL, such as the phone feature below.
Uri uri = Uri.parse("tel:13800138000"); Intent it = newIntent(Intent.ACTION_DIAL, uri); startActivity(it);

5. Resource file (Resource)

The resource files in Android are powerful, images, descriptive text, page layouts, styles, etc. can all be placed in the resource file. The R object in the program can fetch the corresponding ID of each resource, which is a constant that is automatically generated by the system, and you can find the corresponding definition under the R.java in the Gen directory. The corresponding resources can be obtained by getresources () plus R objects in the program.

6. Use of the GridView and ListView

The program is inseparable from the data, and the general multi-data interface can not be separated from grid or list. The two controls in Android are similar to. NET DataGrid and DataList, need to give them a data source, but their data source is much more complex than DataSource, their data source is a adapter. In general, we need to rewrite a subclass based on Baseadapter. The GridView item is very similar to the template column for the DataGrid in. NET, which can add a lot of controls to the subkey. The defined and data bindings for these controls need to be implemented in the GetView method in adapter.

    • Write a adapter class, adapter the required data, usually we use a ArrayList to pass it. And in this class, the main thing is to rewrite the GetView method. The way each GridView and ListView item behaves is defined in this method. In this method, you can add controls to each item, or the event that corresponds to the control.
    • Data binding. Pass the data source (usually ArrayList) to a Adapter,gridview or ListView with Setadapter to bind the adapter.
    • The data item is changed and the control is refreshed with the adapter notifydatasetchanged method.

7. SQLite

SQLite I simply use, feel its syntax is using standard SQL syntax, but I only found its table function, did not find a similar view and stored procedures functions. Since data exists somewhere on your phone, unlike SQL Server, we can't create a database in advance. So the usual practice is to write a dbopenhelper of your own, which is a subclass of Sqliteopenhelper, and we need to rewrite its oncreate and Onupgrade methods. To create your own data table the first time you use it. (Use the CREATE TABLE IF not EXISTS table statement in OnCreate).

(Note: Just saw a netizen's reply, SQLite can create a database beforehand, the way is a bit special, very good.) It is prepared in advance a database file, and then the first time the runtime copy to the corresponding SQLite database directory. You can refer to the following articles. In fact, I would like to start by preparing an XML or text file, the first time the program is run to insert the contents of the XML file into the new table, is it more convenient? Not to worry about which directory the SQLite files are placed in. )
http://www.akasuna.com/2012/03/09/embed-sqlite-database-in-the-apk-of-android-distributed-application/)

8. Tabhost Use

The tab control in Android is not very useful. I would like to write a bottom multiple options, point different options to open different pages of the function, very bad implementation. Finally realized with the tabhost, found a big problem is, open the tab page, and then jump to another sub-page, the bottom of the tab is all missing. Finally looked up a lot of information, said with Groupview or fragment can solve, fragment I have not learned, refer to an online article, with Groupview realized

http://hkp.iteye.com/blog/1185482

9. PhoneGap

A very powerful thing, claiming to be a multi-platform development architecture. I used it to write a few simple pages that were very well implemented. Can do real with HTML5 + JavaScript to write Android program, it can use JavaScript call Android API, such as call contact data, telephone, SMS, camera, SQLite database and so on. Especially with jquery mobile, writing some web-based data programs, very simple, the page is very beautiful. But the page I wrote on it, I tried it on the simulator, as if there was a delay of almost a second, and the speed was much worse than the native program.

10. Asynchronous acquisition of network data and reading and writing of files

Is learning ...

List of commentsReply Reference#1楼2013-02-19 17:11 walklineWeb apps developed with PhoneGap slow support (0) objection (0)Reply Reference#2楼2013-02-19 17:13 It cubNot bad.. Very powerful! I haven't gone to get Android yet. A few days ago. Development Support for window phone (0) objection (0)Reply Reference#3楼2013-02-20 08:20 XiaochaoYou are wrong, SQLite can create a database in advance

http://www.akasuna.com/2012/03/09/embed-sqlite-database-in-the-apk-of-android-distributed-application/Support (0) against ( 0)Reply Reference#4楼 [Landlord] 2013-02-20 08:30 Don't move .@ Xiaochao
reference You are wrong, SQLite can create a database in advance

http://www.akasuna.com/2012/03/09/embed-sqlite-database-in-the-apk-of-android-distributed-application/

Study, very good information. Thank you! Support (0) objection (0)Reply Reference#5楼2013-02-20 08:47 XiaochaoSQLite file directory name, in fact, is "/data/data/{app package name}/databases/", is fixed dead, obviously pre-prepared to contain data of the database convenient AH.

If you have more data, tens of thousands of or more data, it's too time-consuming to insert data.

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.