Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the practical habits in Android?

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is to share with you about the practical habits in Android, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

1. All classes define TAG for ease of debugging. Log is recorded in all methods (or at the beginning of critical steps).

Class TestService extends SuperClass {private static final String TAG = "text.TestService"; / / some code... Private void method1 () {Log.i (TAG, "method1"); / / some code... }}

2. In Activity, many controls have events such as click, and it seems messy to register each control. You can let Activity implement OnXXXXListener. In the onXXX () method, the process is unified.

Class MyActivity extends Activity implements OnClickListener {

/ / some code

Public void onCreate (Bundle savedInstanceState) {

InitComponent ()

RegisterListenr ()

}

Private void initComponent () {

MTextView = (TextView) findViewById (R.id.id1)

MTextView2 = (TextView) findViewById (R.id.id2)

/ / some code

}

Private void registerListener () {

MTextView.setOnClickListener (this)

MTextView.setOnClickListener (this)

}

Private boolean onClick (View v...) {

Switch (v.getId ()) {

Case R.id.id1:

Break

Case R.id.id2:

Break

Default:

Log....

}

}

}

3. Reuse layout layout files by include as far as possible. Easy to manage, save time and keep the code simple.

4. Use style to uniformly set the properties of the control. In order to avoid inconsistent style, but also save code.

5. No mixing is used before the official package is released. Otherwise, you will not be able to view the log after testing the bug. You can only see a.b.c.

These are the practical habits in Android, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report