《Professional.Android.2.Application.Development》摘抄

来源:互联网 发布:电视怎样连接网络 编辑:程序博客网 时间:2024/04/24 23:58

(Page 68)

 

What does this mean in terms of software design? Make sure that your application:

 

Is well behaved Start by ensuring that your Activities suspend when they’re not in the fore-
ground. Android triggers event handlers when your Activity is suspended or resumed so you
can pause UI updates and network lookups when your application isn’t visible—there’s no
point updating your UI if no one can see it. If you need to continue updating or processing in
the background, Android provides a Service class designed to run in the background without
the UI overheads.

 

➤ Switches seamlessly from the background to the foreground With the multitasking nature
of mobile devices, it’s very likely that your applications will regularly move into and out of
the background. It’s important that they ‘‘come to life’’ quickly and seamlessly. Android’s
nondeterministic process management means that if your application is in the background,
there’s every chance it will get killed to free resources. This should be invisible to the user.
You can ensure seamlessness by saving the application state and queuing updates so that your
users don’t notice a difference between restarting and resuming your application. Switching
back to it should be seamless, with users being shown the exact UI and application state they
last saw.

 

Is polite Your application should never steal focus or interrupt a user’s current activity.
Use Notifications and Toasts (detailed in Chapter 9) instead to inform or remind users that
their attention is requested, if your application isn’t in the foreground. There are several ways
for mobile devices to alert users. For example, when a call is coming in, your phone rings;
when you have unread messages, the LED flashes; and when you have new voice mail, a small
‘‘mail’’ icon appears in your status bar. All these techniques and more are available through
the notification mechanism.

 

Presents a consistent user interface Your application is likely to be one of several in use
at any time, so it’s important that the UI you present is easy to use. Don’t force users to
interpret and relearn your application every time they load it. Using it should be simple,
easy, and obvious—particularly given the limited screen space and distracting user
environment.

 

Is responsive Responsiveness is one of the most important design considerations on
a mobile device. You’ve no doubt experienced the frustration of a ‘‘frozen’’ piece of
software; the multifunctional nature of a mobile makes this even more annoying. With the
possibility of delays caused by slow and unreliable data connections, it’s important that your
application use worker threads and background services to keep your activities responsive
and, more importantly, to stop them from preventing other applications from responding
promptly.

 


(Page 69)

The Android design philosophy demands that applications be designed for:
➤ Performance
➤ Responsiveness
➤ Seamlessness
➤ Security

 


(Page 77)

ANDROID DEVELOPMENT TOOLS

 

➤ The Android SDK and Virtual DeviceManager

➤ The Android Emulator

➤ Dalvik DebugMonitoring Service (DDMS)

➤ Android Asset Packaging Tool (AAPT)

➤ Android Debug Bridge (ADB)

 

The following additional tools are also available:

➤ SQLite3

➤ Traceview

➤ MkSDCard

➤ Dx

 


 

(Page 84)

The following six components provide the building blocks for your applications:

➤ Activities

➤ Services

➤ Content Providers

➤ Intents

➤ Broadcast Receivers

➤ Widgets

➤ Notifications

 

 


 

(Page 86)

The following list gives a summary of the available <manifest> node tags, and an XML snippet demonstrating how each one is used:

➤ uses-sdk Using a combination of minSDKVersion , maxSDKVersion , and targetSDKVersion attributes you can
restrict which devices your application can run on, based on the SDK version supported by
the installed platform.

  • The minimum SDK version specifies the lowest version of the SDK that includes the APIs you have used in your application.
  • The maximum SDK version lets you define an upper limit you are willing to support.
  • The target SDK version attribute lets you specify the platform against which you did your development and testing.

 

 

➤ uses-configuration Use uses-configuration nodes to specify each combination of input mechanisms supported by your application. You can specify any combination of input devices that include:

  • reqFiveWayNav Specify true for this attribute if you require an input device capable of navigating up , down , left , and right and of clicking the current selection. This includes both trackballs and D-pads .
  • reqHardKeyboard If your application requires a hardware keyboard specify true .
  • reqKeyboardType Lets you specify the keyboard type as one of nokeys , qwerty ,twelvekey ,or undefined .
  • reqNavigation Specify the attribute value as one of nonav , dpad , trackball ,wheel ,or undefined as a required navigation device.
  • reqTouchScreen Select one of notouch , stylus , finger ,or undefined to specify the required touchscreen input.

➤ uses-feature Use multiple uses-feature nodes to specify each of the hardware features your application requires. This will prevent your application from being installed on a device that does not include a required hardware feature.

 

➤ supports-screens

  • smallScreens Screens with a resolution smaller than traditional HVGA—typi-cally QVGA screens.
  • normalScreens Used to specify typical mobile phone screens of at least HVGA,includingWVGA andWQVGA.
  • largeScreens Screens larger than normal. In this instance a large screen is considered to be significantly larger than a mobile phone display.
  • anyDensity Set to true if your application can be scaled to accommodate any screen resolution.

 

➤ application It uses attributes to specify the metadata for your application (including its title, icon, and theme).The <application> node also acts as a container that includes the Activity, Service, Content Provider, and Broadcast Receiver tags used to specify the application components.

 

  • activity

  • service

  • provider

  • receiver

➤ uses-permission As part of the security model, uses-permission tags declare the permissions you’ve determined your application needs to operate properly.

➤ permission Within the permission tag, you can specify the level of access the permission will permit (normal, dangerous, signature, signatureOrSystem), a label, and an external resource containing the description that explains the risks of granting the specified permission.

➤ instrumentation Instrumentation classes provide a test framework for your application components at run time.

 


APPLICATION PRIORITY (Page 92)

➤ Active processes(Critical Priority Level 1)

Active (foreground) processes have application components interacting with the user. These are the processes Android is trying to keep responsive by reclaiming resources.There are generally very few of these processes,
and they will be killed only as a last resort. 

 

      Active processes include:

  • Activities in an ‘‘active’’ state;
  • Broadcast Receivers executing onReceive event handlers.
  • Services executing onStart, onCreate,or onDestroy event handlers.
  • Running Services that have been flagged to run in the foreground.

➤ Visible processes(High Priority Level 2)

Visible but inactive processes are those hosting ‘‘visible’’ Activities.They’ll be killed only under extreme circumstances to allow active processes to continue.

 

➤ Started Service processes(High Priority Level 3)

Processes hosting Services that have been started.They are still considered foreground processes and won’t be killed unless resources are needed for active or visible processes.

 

➤ Background processes(Low Priority Level 4)

Android will kill using a last-seen-first-killed pattern in order to obtain resources for foreground processes.

 

➤ Empty processes(Low Priority Level 5)

 


 

Animations(98)

Android supports two types of animation. Tweened animations can be used to rotate, move, stretch,
and fade a View; or you can create frame-by-frame animations to display a sequence of Drawable
images.

    Tweened Animations

    An animation can be defined for changes in alpha (fading), scale (scaling), translate (movement), or rotate (rotation).

➤ duration Duration of the animation in milliseconds.

➤ startOffset Millisecond delay before the animation starts.

➤ fillBefore true to apply the animation transformation before it begins.

➤ fillAfter true to apply the animation transformation after it ends.

➤ interpolator Sets how the speed of this effect varies over time.

TABLE 3-1: Animation type attributes(Page 99)

--INTRODUCING THE ANDROID APPLICATION CLASS(Page 108)to be continued....

 

原创粉丝点击