`
nanjingjiangbiao_T
  • 浏览: 2688435 次
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

给android新手的10条建议

 
阅读更多

Learn SQL and put your data models in a database

了解SQL并将你的数据模型放到数据库

Android has an excellent persistence system; use it to make your applications more robust in case of failure or shutdown, and to make suspending and resuming more efficient. Android'sSQLite-based storage system is thoroughly integrated with Android's user interface classes.

Android supports the observer pattern in Cursor, Adapter, and View classes, enabling the user interface to connect directly to the results of database queries. Using these capabilities means less work when Android wants to stop your application because you have little or no data that needs to be to be explicitly saved, and more reliability in running on mobile devices that can be out of battery at any time.

The database classes in the Android framework manage caching and are more efficient than reading a whole data model into objects in memory.

But, in oder to take maximum advantage of the Android way of designing data models, you will need to know someSQL.

Learn XML

了解XML

You don't have to know much about XML to use the visual editing tools for defining layouts and other resources. You are, in theory, hardly ever required to edit XML "by hand." But these tools are imperfect. The more you know about how Android uses XML, and about the Android XML schema, the easier it is to fix problems that occur in XML in Android applications, and the more comfortable you will be using XML to maximum effect in developing Android applications. A general XML book, likeXML in a Nutshell (O'Reilly), or Learning XML (O'Reilly) can be useful.

Learn Eclipse's features and foibles

了解Eclipse的一些优缺点

Java can be a verbose language, and without code completion, Javadoc pop-ups, and advanced refactoring, it can be a drag compared to dynamic languages. In other words, Java without Eclispe's productivity features would be no fun at all.

Eclipse, however, can have a steep learning curve for beginners. Getting comfortable with this big, powerful, and sometimes perplexing IDE is a big part of being productive in Android application development. Steve Holzner's book Eclipse (O'Reilly) is an excellent introduction and will get you up to speed.

Within the Eclipse documentation pages, you can get a good start by reading the pages covering Eclipseconcepts. Get to know these concepts early on, otherwise the Eclipse menus and documentation will seem full of jargon. Then go on to thebasic tutorial in the Java development section.

Use automated testing

使用自动化测试

Use the Monkey to stress test your application. It generates a stream of events, simulating random inputs, and reports application crashes or lack of response.

Use the Instrumentation Framework and JUnit to write unit tests that can be run from Eclipse using adb and the InstrumentationTestRunner.

Be a good citizen in the society of Android applications

在android应用社区,做一个好的公民

Learn and use the application and service lifecycles effectively. Enable your application to be efficiently stopped and restarted by the Android system. Unlike many runtime environments with almost trivial application lifecycles, Android's runtime environment frequently stops or terminates processes to keep application resource consumption low, being prepared to restart them if the user navigates back to an application.

Android expects applications to override and respond to a set of application lifecycle methods and cooperate with the way Android manages applications as they become visible on the screen or are obscured by other applications. Get this code into your application early on in its development, so that you do not end up retro-fitting these method overrides. Use the debugger to set breakpoints in the application lifecycle methods so that you get a feel for how the Android application lifecycle works.

Advanced tips

Use static analyzers

Java lends itself well to meaningful compiler warnings, and to warnings and "advice" based on static analysis. Every potential bug you kill before your application leaves development brings you closer to a 4-star user rating instead of a 2-star one. Use the compiler warnings,FindBugs, and try other static analyzers, like PMD available as Eclipse plug-ins to find the tools that find the most problems and the fewest false positives.

Use and be used

Use Intent objects and StartActivity (and related methods) to "borrow" functionality from other applications, and write your application to respond toIntent filter matches and provide functionality to other applications. Appications can also share data through theContentProvider system and through remote method interfaces.

Divide large applications

If you are writing a large application, consider dividing it into a suite of applications and services. Smaller applications load faster and use fewer resources. Making a suite of applications, content providers, and services makes your code more open to incorporation into other applications as described the "Use and be used" tip.

Design for low power consumption(设计程序时考虑到电量消耗)

Things that are benign on a personal computer, like polling a server every 10 minutes, can cut a handset's battery life in half or worse. Code your application to do as little as possible until the user brings it to the foreground or some external information arrives that requires action.

Use the "Battery use" in the "About phone" menu in "Settings" to find the applications and other system functions using the battery.

Use the NDK to access library functions

The Android NDK is an optional companion to the Android SDK that enables use of native compiled code. Use the NDK to incorporate existing C and C++ libraries where they provide useful functionality. Code CPU-intensive computations, if they must be done on the handset, in C or C++. Use the NDK's tools to call that code from Java using the Java Native Interface (JNI).

Tips for good user interfaces

In addition to the tens tips above, here are some tips for creating a better user experience on Android:

Avoid depending on specific dimensions

Avoid assuming anything about screen size and screen resolution. Specify layouts so that they adapt to changes in screen size. Specify dimensions inresolution-independent units, not in pixels, which may be much bigger or smaller on screens with different resolutions. Make sure your application works equally well in horizontal and veritcal orientations, and with or without an on-screen keyboard displayed. Configure the emulator to test different screen sizes and resolutions.

If your application includes bitmap graphics that don't look good resized - e.g., highly detailed game sprites - include small, medium, and large variants for different screen resolutions, and if your application needs specific screen sizes, usemanifest attributes to indicate these requirements to the Android system.

Enable direct manipulation

Direct manipulation means enabling the users to perform operations in an intuitive way directly on what they see. If the user can trigger an action on an object bydragging it to a place on the screen, or if a menu appears in the context of an object when the user long-presses it, that is direct manipulation.

The opposite of direct manipulation is a rigid sequence of operations, or a cascading model where the user descends into a hierarchy of dialogs and is trapped until he or she completes a sequence of operations.

Which would you rather use? Be kind to your users and enable direct manipulation wherever you can. This can be challenging on a small screen, but the reward is correspondingly large. Direct manipulation is your most powerful tool for keeping a user interface simple and friendly, and minimizing the number of different screens a user must visit in your application.

Avoid hierarchy

Don't design your application around a central location, "home" screen, or fixed starting place. Mobile device users want instant access to functionality. They won't tolerate moving up and down menu hierarchies. Furthermore, you want to provide stand-alone activities that are easy for other applications to invoke through the Intent interface. Allow each activity to be used independently, and include a menu in it that allows access to every other activity. In short, embed your application into a seamless Android user experience.

Internationalize early

This will prevent you from getting lazy and embedding strings in your code. Android supports 26 Locales, and will provide more support forinternationalization in the future - externalize your strings now and save yourself the pain later.

Learn SQL and put your data models in a database

了解SQL并将你的数据模型放到数据库

Android has an excellent persistence system; use it to make your applications more robust in case of failure or shutdown, and to make suspending and resuming more efficient. Android'sSQLite-based storage system is thoroughly integrated with Android's user interface classes.

Android supports the observer pattern in Cursor, Adapter, and View classes, enabling the user interface to connect directly to the results of database queries. Using these capabilities means less work when Android wants to stop your application because you have little or no data that needs to be to be explicitly saved, and more reliability in running on mobile devices that can be out of battery at any time.

The database classes in the Android framework manage caching and are more efficient than reading a whole data model into objects in memory.

But, in oder to take maximum advantage of the Android way of designing data models, you will need to know someSQL.

Learn XML

了解XML

You don't have to know much about XML to use the visual editing tools for defining layouts and other resources. You are, in theory, hardly ever required to edit XML "by hand." But these tools are imperfect. The more you know about how Android uses XML, and about the Android XML schema, the easier it is to fix problems that occur in XML in Android applications, and the more comfortable you will be using XML to maximum effect in developing Android applications. A general XML book, likeXML in a Nutshell (O'Reilly), or Learning XML (O'Reilly) can be useful.

Learn Eclipse's features and foibles

了解Eclipse的一些优缺点

Java can be a verbose language, and without code completion, Javadoc pop-ups, and advanced refactoring, it can be a drag compared to dynamic languages. In other words, Java without Eclispe's productivity features would be no fun at all.

Eclipse, however, can have a steep learning curve for beginners. Getting comfortable with this big, powerful, and sometimes perplexing IDE is a big part of being productive in Android application development. Steve Holzner's book Eclipse (O'Reilly) is an excellent introduction and will get you up to speed.

Within the Eclipse documentation pages, you can get a good start by reading the pages covering Eclipseconcepts. Get to know these concepts early on, otherwise the Eclipse menus and documentation will seem full of jargon. Then go on to thebasic tutorial in the Java development section.

Use automated testing

使用自动化测试

Use the Monkey to stress test your application. It generates a stream of events, simulating random inputs, and reports application crashes or lack of response.

Use the Instrumentation Framework and JUnit to write unit tests that can be run from Eclipse using adb and the InstrumentationTestRunner.

Be a good citizen in the society of Android applications

在android应用社区,做一个好的公民

Learn and use the application and service lifecycles effectively. Enable your application to be efficiently stopped and restarted by the Android system. Unlike many runtime environments with almost trivial application lifecycles, Android's runtime environment frequently stops or terminates processes to keep application resource consumption low, being prepared to restart them if the user navigates back to an application.

Android expects applications to override and respond to a set of application lifecycle methods and cooperate with the way Android manages applications as they become visible on the screen or are obscured by other applications. Get this code into your application early on in its development, so that you do not end up retro-fitting these method overrides. Use the debugger to set breakpoints in the application lifecycle methods so that you get a feel for how the Android application lifecycle works.

Advanced tips

Use static analyzers

Java lends itself well to meaningful compiler warnings, and to warnings and "advice" based on static analysis. Every potential bug you kill before your application leaves development brings you closer to a 4-star user rating instead of a 2-star one. Use the compiler warnings,FindBugs, and try other static analyzers, like PMD available as Eclipse plug-ins to find the tools that find the most problems and the fewest false positives.

Use and be used

Use Intent objects and StartActivity (and related methods) to "borrow" functionality from other applications, and write your application to respond toIntent filter matches and provide functionality to other applications. Appications can also share data through theContentProvider system and through remote method interfaces.

Divide large applications

If you are writing a large application, consider dividing it into a suite of applications and services. Smaller applications load faster and use fewer resources. Making a suite of applications, content providers, and services makes your code more open to incorporation into other applications as described the "Use and be used" tip.

Design for low power consumption(设计程序时考虑到电量消耗)

Things that are benign on a personal computer, like polling a server every 10 minutes, can cut a handset's battery life in half or worse. Code your application to do as little as possible until the user brings it to the foreground or some external information arrives that requires action.

Use the "Battery use" in the "About phone" menu in "Settings" to find the applications and other system functions using the battery.

Use the NDK to access library functions

The Android NDK is an optional companion to the Android SDK that enables use of native compiled code. Use the NDK to incorporate existing C and C++ libraries where they provide useful functionality. Code CPU-intensive computations, if they must be done on the handset, in C or C++. Use the NDK's tools to call that code from Java using the Java Native Interface (JNI).

Tips for good user interfaces

In addition to the tens tips above, here are some tips for creating a better user experience on Android:

Avoid depending on specific dimensions

Avoid assuming anything about screen size and screen resolution. Specify layouts so that they adapt to changes in screen size. Specify dimensions inresolution-independent units, not in pixels, which may be much bigger or smaller on screens with different resolutions. Make sure your application works equally well in horizontal and veritcal orientations, and with or without an on-screen keyboard displayed. Configure the emulator to test different screen sizes and resolutions.

If your application includes bitmap graphics that don't look good resized - e.g., highly detailed game sprites - include small, medium, and large variants for different screen resolutions, and if your application needs specific screen sizes, usemanifest attributes to indicate these requirements to the Android system.

Enable direct manipulation

Direct manipulation means enabling the users to perform operations in an intuitive way directly on what they see. If the user can trigger an action on an object bydragging it to a place on the screen, or if a menu appears in the context of an object when the user long-presses it, that is direct manipulation.

The opposite of direct manipulation is a rigid sequence of operations, or a cascading model where the user descends into a hierarchy of dialogs and is trapped until he or she completes a sequence of operations.

Which would you rather use? Be kind to your users and enable direct manipulation wherever you can. This can be challenging on a small screen, but the reward is correspondingly large. Direct manipulation is your most powerful tool for keeping a user interface simple and friendly, and minimizing the number of different screens a user must visit in your application.

Avoid hierarchy

Don't design your application around a central location, "home" screen, or fixed starting place. Mobile device users want instant access to functionality. They won't tolerate moving up and down menu hierarchies. Furthermore, you want to provide stand-alone activities that are easy for other applications to invoke through the Intent interface. Allow each activity to be used independently, and include a menu in it that allows access to every other activity. In short, embed your application into a seamless Android user experience.

Internationalize early

This will prevent you from getting lazy and embedding strings in your code. Android supports 26 Locales, and will provide more support forinternationalization in the future - externalize your strings now and save yourself the pain later.
分享到:
评论

相关推荐

    basic4android新手指南

    ### Basic4Android新手指南 #### 一、Basic4Android简介 **Basic4Android**是一款专为Android设备设计的集成开发环境(IDE),它提供了一种简单而强大的方式来开发应用程序。该工具支持多种语言特性,其中语法类似...

    Android开发新手入门教程,开发流程,开发建议

    Android开发新手入门教程,开发流程,开发建议

    android_新手教程

    ### Android新手教程知识点总结 #### 一、Android系统概述 - **定义**: Android是一个基于Linux内核的操作系统,由Google公司开发,旨在为移动设备提供一个开放和完整的软件平台。 - **特点**: 开源性、可定制性高...

    android新手入门经典案例源码

    "android新手入门经典案例源码"正是一份适合初学者的宝贵资源,它包含了一系列精心设计的实例,帮助初学者理解并运用Android应用开发的核心技术。下面将详细阐述这些案例可能涉及的知识点,以及它们对学习者的重要性...

    Android程式编写及调试新手入门

    本文档详细介绍了Android新手入门所需具备的知识点,包括必要的开发工具准备、自我评估的方法、学习环境的营造以及通过实战项目学习的方法。对于初学者而言,遵循本文档提供的指南,可以在较短时间内建立起对Android...

    android mapbox地图新手基础 demo

    对于新手来说,了解并掌握Mapbox地图的基本使用是至关重要的。 首先,让我们从安装Mapbox SDK开始。在Android项目中,你可以通过Gradle依赖来引入Mapbox的库。在`build.gradle`文件中添加以下依赖: ```groovy ...

    安卓Android新手必看

    ### 安卓Android新手必看知识点详解 #### 安卓系统概览与代码输入技巧 在探索安卓系统之前,我们先来了解一些基础概念。安卓(Android)是基于Linux内核的操作系统,由Google公司开发并维护,广泛应用于智能手机、...

    android新手实例

    "android新手实例"这个主题恰好提供了这样一个实践平台,让你能够通过实际操作来理解和掌握Android应用开发的基础知识。在这个实例中,我们将探讨Android应用的基本结构、布局设计、事件处理以及源码分析等关键点。 ...

    Android项目源码适合新手的简单闹钟项目蓝宝闹钟.zip

    《Android新手入门:解析“蓝宝闹钟”项目源码》 在移动开发领域,Android以其开源、灵活的特性吸引了大量的开发者。对于初学者来说,理解并实践Android项目源码是提升技能的重要途径。本文将深入探讨一个适合新手...

    [中文]Basic4android新手指南_第2章我的第一个程序(MyFirstProgram.b4a)

    此外,还需要给这些控件命名,建议使用有意义的前缀来表示控件类型及用途,如“lbl”前缀用于Label控件。 整个开发过程要确保设计器连接到模拟器,以便在设计UI布局时可以看到模拟器的实时反馈。完成UI布局设计后,...

    带领新手快发开发android app

    对于希望进入移动应用开发领域的新手而言,快速掌握Android App开发技能变得尤为重要。Android App开发主要涉及Java或Kotlin语言的应用编程接口(API)来构建应用程序,并利用Android Studio这一集成开发环境(IDE)...

    基于 android 的Android作业(android毕业设计,包括源码、数据库).zip

    Android 毕业设计,前后端分离,含有代码注释,新手也可看懂。毕业设计、期末大作业、课程设计、高分必看,下载下来简单部署就可以使用。 包含:项目源码、数据库脚本、软件工具等,该项目可以作为毕设、课程设计...

    Android模拟器及编译环境安装新手入门.pdf

    本文将详细讲解这个过程,帮助新手快速上手。 一、Android Studio安装与初始化 Android Studio是Google官方推出的Android开发集成环境,包含了所有必要的工具,如SDK Manager、AVD Manager等。首先,从Google官网...

    基于android的图书借阅系统(android毕业设计,包括源码、数据库).zip

    Android 毕业设计,前后端分离,含有代码注释,新手也可看懂。毕业设计、期末大作业、课程设计、高分必看,下载下来简单部署就可以使用。 包含:项目源码、数据库脚本、软件工具等,该项目可以作为毕设、课程设计...

    基于Android的宿舍管理系统(android毕业设计,包括源码、数据库).zip

    Android 毕业设计,前后端分离,含有代码注释,新手也可看懂。毕业设计、期末大作业、课程设计、高分必看,下载下来简单部署就可以使用。 包含:项目源码、数据库脚本、软件工具等,该项目可以作为毕设、课程设计...

    android几本好书

    这本书专注于Android应用的性能优化,提供了许多实用的技巧和建议,帮助开发者创建高效、流畅的应用。 6. **《Head First Android Development》** 作者:Dawn Griffiths、David Griffiths 采用直观、生动的...

    基于android的城市智能交通软件系统(android毕业设计,包括源码、数据库).zip

    Android 毕业设计,前后端分离,含有代码注释,新手也可看懂。毕业设计、期末大作业、课程设计、高分必看,下载下来简单部署就可以使用。 包含:项目源码、数据库脚本、软件工具等,该项目可以作为毕设、课程设计...

    android新手8天理解安卓 视频(1-67)

    这套教学视频涵盖了Android开发的基础理论知识到实际开发过程中的常见问题解决方案,对于想要快速入门Android开发的新手来说非常实用。通过系统学习,可以有效提升个人技能水平并为将来从事相关领域工作打下坚实基础...

Global site tag (gtag.js) - Google Analytics