`
baobaoupup
  • 浏览: 471898 次
文章分类
社区版块
存档分类
最新评论

sdk reading notes

 
阅读更多

1.

Declaring Layout

To measure its dimensions, a view takes into account its padding.

Padding can be used to offset the content of the view by a specific amount of pixels

Even though a view can define a padding, it does not provide any support for margins. However, view groups provide such a support. Refer to ViewGroup and ViewGroup.MarginLayoutParams for further information

It is possible to retrieve the location of a view by invoking the methods getLeft() and getTop() .

For instance, when getLeft() returns 20, that means the view is located 20 pixels to the right of the left edge of its direct parent.

In general, the XML vocabulary for declaring UI elements closely follows the structure and naming of the classes and methods, where element names correspond to class names and attribute names correspond to methods

Handling UI Events

onTouch() - This returns a boolean to indicate whether your listener consumes this event. The important thing is that this event can have multiple actions that follow each other. So, if you return false when the down action event is received, you indicate that you have not consumed the event and are also not interested in subsequent actions from this event. Thus, you will not be called for any other actions within the event, such as a finger gesture, or the eventual up action event.

Note: Android will call event handlers first and then the appropriate default handlers from the class definition second. As such, returning true from these event listeners will stop the propagation of the event to other event listeners and will also block the callback to the default event handler in the View. So be certain that you want to terminate the event when you return true .

Service API changes starting with Android 2.0

Consider this typical scenario:

  1. An application calls startService().
  2. That service gets onCreate(), onStart(), and then spawns a background thread to do some work.
  3. The system is tight on memory, so has to kill the currently running service.
  4. Later when memory is free, the service is restarted, and gets onCreate() called but not onStart() because there has not been another call to startService() with a new Intent command to send it.

Now the service will sit there created, not realizing it used to be doing some work, and so not knowing it should stop itself at some point.

To address this, in Android 2.0 Service.onStart() as been deprecated (though still exists and operates as it used to in previous versions of the platform). It is replaced with a new Service.onStartCommand() callback that allows the service to better control how the system should manage it. The key part here is a new result code returned by the function, telling the system what it should do with the service if its process is killed while it is running:

Once you start targeting API version 5 or later, the default mode is START_STICKY and you must be prepared to deal with onStart() or onStartCommand() being called with a null Intent.

http://android-developers.blogspot.com/2010/02/service-api-changes-starting-with.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics