Common Tips for Android projects

Source: Internet
Author: User

Chapter1 prepare to work one, optimize your working range (sharpening does not mistake chopping power)

Digression: There may be a lot of people who think that now that Google has abandoned eclipse support and switched to Android Studio, this section doesn't seem to make sense. In fact, from a philosophical point of view: Everything is a universal regularity! May operate on as is different, but we have to have such a general idea, then through Google we can still find the corresponding operation and complete their own workspace customization, not to mention we have two years of work experience in the Android Developer!!! So it is imperative to master Ecipse!

1. Customize your own development window


I believe that the students are familiar with such a development window, the specific function of each window I do not introduce each, I personally recommend the development of their own window into this, because really can save a lot of time. The comrades who finished the window customization must not want their work space to be messy because of the clutter. Then we need to say that this state of preservation, convenient later recovery. Take a look at the following operation, you can easily solve the problem.

1.1 Save your own Development window view

We can save the window as Androidso that we can see our saved view on the interface.

1.2 Recovering your own development window

After doing this, we never have to worry about our view being messed up. Once the window is lost, we can go directly to the Window->reset perspective operation to revert to our previous development interface. Of course, similar methods can be used in the debug view and so on ...

Ii. Customizing your own templates and tool classes

It's pretty simple, isn't it? With such a development window, we can achieve efficient development on top of it. How do we develop our applications efficiently?

Custom Development Template "Code Templates"

Open Windows->preferences->java->editor->templates

' psfi:public static final int I${cursor} = 0; Psfs:public static final String S${cursor} = "S"; ToastT:Toast.makeText (This, "${cursor}", Toast.length_short). Show ();  Findt:view View = Findviewbyid (R.id.${cursor});  Intentt:intent Intent = new Intent (${cursor});  Startt:intent Intent = new Intent (this, ${cursor}.class); startactivity (Intent);    Oncreatet: @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.${cursor});}    Viewholdert:static class Viewholder {ImageView icon;  TextView name;}        Convertviewt:viewholder holder = null;                    if (Convertview = = null) {//Initialize View Convertview = view.inflate (Mcontext, r.layout.item_${cursor},            NULL);            Initialize Control holder = new Viewholder ();            Holder.icon = (ImageView) Convertview.findviewbyid (R.id.item_icon);            Holder.name = (TextView) Convertview.findviewbyid (r.id.item_name); Save VIEwholder Convertview.settag (holder);        } else {//get Viewholder Holder = (viewholder) Convertview.gettag () from the multiplexed view;        }//Bind data mdata.get (position);        Holder.icon.setImageDrawable (Data.geticon ());        Holder.name.setText (Data.getname ());   return convertview;

`
With these templates, when we enter these common code, we can directly press the alt+/ to complete their own rapid development.

Customizing the Notes Template

Open the parameter Settings panel from the menu window->preference and select: Java--code Style, code Templates

`Files:/** * 黑马程序员 * http://www.itheima.com/ * * @date ${date}${time} * @version V1.0 */Types:/** * @Description: ${todo}(这里用一句话描述这个类的作用) * @author ${user} * @date ${date} ${time}  */`

In this way, we can easily add our own annotations through alt+shift+j in the class, of course, more personalized comments can be consulted:
http://chenzhou123520.iteye.com/blog/1625629
In this way, we can use the same annotations when we develop the team, and avoid a lot of personal comments that do not understand the problem.

Custom tool Classes

In development we avoid having to print some of our own logs, or save your own content to shared_pref. Then we need two easy-to-use tool classes to avoid repeating the wheel-building work.

1. Log Tool class
' Package com.tzl.demo.utils;import android.util.log;/** * @Description Log Tool class, control the printing of logs * @author JOHN * @date 2016-4-12 * *     The public class L {/** * Log print switch can be initialized in the application OnCreate function.    */public static Boolean DEBUG = true;    Generic label name public static final String tag = "tag";     /** * Avoid instantiation of external and class */Private L () {throw new Unsupportedoperationexception ("L can not be instantiated!");        public static void V (String tag,string msg) {if (DEBUG) {LOG.V (tag, msg);        }} public static void V (String msg) {if (DEBUG) {log.v (TAG, msg);        }} public static void D (String tag,string msg) {if (DEBUG) {LOG.D (tag, msg);        }} public static void D (String msg) {if (DEBUG) {log.d (TAG, msg);        }} public static void I (String tag,string msg) {if (DEBUG) {LOG.I (tag, msg);       }} public static void I (String msg) {if (DEBUG) {     LOG.I (TAG, msg);        }} public static void W (String tag,string msg) {if (DEBUG) {LOG.W (tag, msg);        }} public static void W (String msg) {if (DEBUG) {LOG.W (TAG, msg);        }} public static void E (String tag,string msg) {if (DEBUG) {LOG.E (tag, msg);        }} public static void E (String msg) {if (DEBUG) {log.e (TAG, msg); }    }}`
2. Preferences Tool Class
' Package Com.tzl.demo.utils;import android.content.context;import android.content.sharedpreferences;/** *@ Description Preferences Action Tool class * @author JOHN * @date 2016-5-5 */public class S {private static final String file_name = "Sp_confi    G ";     /** * Avoid instantiation of outside and class */private S () {throw new Unsupportedoperationexception ("S can not is instantiated!"); }/** * Method of saving data, we need to get the specific type of data saved, and then call different save method according to the type * @param context * @param key * @param object * /public static void Putparam (context context, string key, Object object) {String type = Object.getclass (). GetS        Implename ();        Sharedpreferences sp = context.getsharedpreferences (file_name, context.mode_private);        Sharedpreferences.editor Editor = Sp.edit ();        if (String.class.getSimpleName (). Equals (type)) {editor.putstring (key, (String) object);        } else if (Integer.class.getSimpleName (). Equals (type)) {Editor.putint (key, (Integer) object); } elseif (Boolean.class.getSimpleName (). Equals (type)) {Editor.putboolean (key, (Boolean) object);        } else if (Float.class.getSimpleName (). Equals (type)) {Editor.putfloat (key, (Float) object);        } else if (Long.class.getSimpleName (). Equals (type)) {Editor.putlong (key, (Long) object);    } editor.commit (); }/** * Get the method to save the data, we based on the default value to save the specific type of data, and then call the relative method to get the values * @param context * @param key keyword * @param defaulto        Bject Default Value * @return */public static object GetParam (context context, String key, Object Defaultobject) {        String type = Defaultobject.getclass (). Getsimplename ();        Sharedpreferences sp = context.getsharedpreferences (file_name, context.mode_private);        if (String.class.getSimpleName (). Equals (type)) {return sp.getstring (key, (String) defaultobject);        } else if (Integer.class.getSimpleName (). Equals (type)) {return Sp.getint (key, (Integer) defaultobject); }        else if (Boolean.class.getSimpleName (). Equals (type)) {return Sp.getboolean (key, (Boolean) defaultobject); } else if (Float.class.getSimpleName (). Equals (type)) {return sp.getfloat (key, (Float) Defaultobjec        T);        } else if (Long.class.getSimpleName (). Equals (type)) {return Sp.getlong (key, (Long) defaultobject);    } return null; }    }    `

These two tool classes are also written through the guidance of Nan brother. Of course, we can also refer to some of the online wording, we can together to improve the tool.

Here's another thing to mention:

1. For the above settings because of the length of the reasons, we can not introduce a very comprehensive, but each knowledge point I believe that the work is very practical skills. If you need it, we can use Google settings.

2. There are some students may think, we have worked hard to set up a half-day work space, and so I switch the working range is gone! Of course, the Eclipse developers have long considered this issue, and we just need to talk about the. Metadata folder in the current workspace to the new workspace and then restart your eclipse to get what you've set up.

3. Of course, research on the collection and mechanism of some tool classes I will write it in a project similar to Apidemos. So when it's time to use it in development, we can just use CV Dafa to get it done. After all, efficiency is still very important ~ ~ ~, here hope that interested students can contact me through the QQ, there is a good saying: Crowds! Only in this way can our demo be collected as soon as possible the more comprehensive well

4. Corresponding to the tasks you have not completed we must add TODO. To add annotations, it's also good for the development of our project.

5.* Remember some commonly used shortcut keys, this is not summed up, used to write down the good

6. Above the operation I believe in the AS2.1 will have, we can follow similar rules to find the next, here because of the time, I do not describe it, I hope that in the future in the article we will learn together.

Chapter2 Open the road to development (the Road of Kings) before development we need to develop a sense of right:
1.api没你想象的那么重要(记住业务使用的核心类就好),重点把握业务逻辑和代码架构搞好,如果可能的话最好搞清楚内部的机制原理,撸一把源码,写一个自己的框架。2.发生错误要学会自己解决(Debug+LogCat+文档),自己解决不了Google,Google不了整理下思路问身边比你牛B的人(最好给自己解决问题设置个时限,如果一个比较棘手的问题解决超过半个小时搞不定,那么暂且搁置下)。3.***第三方框架不要慌,docs打开帮你忙。如果你还是学不会,只能怪你非人类***哈哈,这里开了个玩笑,我们要正确地掌握第三方库的两种导入源码的方法,有了源码和文档,相信我们学起第三方框架来应该会得心应手。导入第三方框架观察源码1.在lib同级目录下面添加properties文件,文件的名字就是需要导入的第三方库.jar.properties,记得重启自己的工程偶2.直接讲第三方库的library文件作为工程导入自己的工作空间。4.工欲善其事,必先利其器。积累一些常用的非常好的网站和工具(反编译工具等等),可以解决你的很多难题!好站集锦:1.在线json转化网站:http://www.bejson.com/,离线json转化工具:HiJson2.源码查看网站:http://www.grepcode.com/  http://androidxref.com/(更吊)3.github4.友盟统计5.有米广告
Build Your own projects
1.代码组织架构  按照功能和业务划分,这里个人认为可能混合使用对于一些比较大型的项目还是挺有好处的。2.事先约定好项目中的命名法则  一般规则:功能模块_业务模块_类型_具体描述  例如:`selector_common_btn_ok`,个人认为我们应该在项目开始前定义好这些命名规范,这样开发起来可以有条不紊。3.写一个JAVA工程,方便测试关于JAVA的一些工具    这个的好处当然是为了去测试一些jdk相关的API,比如我们做过的压缩工具类4.版本控制工具的使用(Svn和Git)(TODO..)    Git的使用还是比较重要的,目前自己还不太熟悉,正在学习掌握中。而对于svn在javaee中比较常用,当然了作为昔日版本控制的王者,很多公司都是有使用的,所以为了融入一些比较传统的开发团队,我们还是有必要去掌握下的!

Note: Changing the encoding set of the workspace

Debug Project: (TODO..)
1.测试类2.debug
On-line operation:
1.**异常捕获机制**2.混淆代码(TODO..)3.镶嵌广告4.签名文件5.打包上线注意:签名文件(.keystore)和密码一定要妥善保存啦!!!

Because of the time relationship, write here! Back to the time to update it, you are welcome to propose to correct the suggestion I ~ ~

Common Tips for Android projects

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.