Some of the tips used in Android development _android

Source: Internet
Author: User

activity.startactivities () is often used to start other activity in the middle of an application.

textutils.isempty () simple tool class for detecting whether null

html.fromhtml () is used to generate an Html, and the argument can be a string. Personally, I don't think it's very fast, so I don't use it very often. (I say it is not often used to highlight this sentence: Please more manually build spannable to replace html.fromhtml), but it's good for rendering text that gets from the Web.

Textview.seterror () is great when validating user input

Build.version_codes This indicates the current version number, which is often used when dealing with compatibility issues. Click in to see the different features of each version

log.getstacktracestring () convenient log-class tools, Methods LOG.V (), LOG.D (), LOG.I (), LOG.W (), and LOG.E () all print information to Logcat. Sometimes you need to insert the wrong information into a database or a custom log file, and then you need to return the error message as a string, that is, when using the static string getstacktracestring (Throwable tr) method .

Layoutinflater.from () as the name suggests, for inflate a layout, the parameter is the ID of the layout. People who write adapter often use more.

viewconfiguration.getscaledtouchslop () uses the values provided in viewconfiguration to ensure that all touch interactions are uniform. The value obtained by this method indicates that the user's hand is sliding at this distance before it is determined to be sliding. Of course, this value can be determined by itself. But for consistency, it's better to use standard values.

Phonenumberutils.convertkeypadletterstodigits as the name suggests. Converts letters to numbers, similar to T9 input methods,

Context.getcachedir () Gets the path to the cached data folder, very simple but not many people know, this path is usually on the SD card (the SD card here refers to the SD card in a broad sense, including external storage and internal storage) adnroid/data/ Your application package name/cache/below. When testing, you can go here to see if the cache is successful. The advantage of caching here is that you don't have to manually create folders, you don't have to worry about deleting folders you create, and when the application unloads, it's empty. When using a third party cleanup tool, this will also be emptied.

argbevaluator is used to process color gradients. As Chris Banes says, this class does a lot of automatic boxing, so it's best to get rid of its logic and implement it yourself. This is not used, unknown why, back to add.

Contextthemewrapper is convenient to modify the theme at run time.

Space Spaces is a new control in Android 4.0 that can actually be used to separate different controls to form a blank area. This is a lightweight view component that can skip draw and is great for any scene that requires a placeholder.

Valueanimator.reverse () This method can successfully cancel a running animation. I love it.

Dateutils.formatdatetime () is used for locale formatting, outputting the time or date of formatting and localization.

alarmmanager.setinexactrepeating is a good way to save power by making a noise grouping, even if you only call an alarm clock (you can make sure that you automatically call Alarmmanager.cancel when you're finished using the )。 The original said that the more abstract, here in detail: Setinexactrepeating refers to the setting of inaccurate alarm clock, the use of methods: Alarmmanager.setinexactrepeating (ALARMMANAGER.RTC, Starttime,intervall, Pendingintent), the inaccurate alarm clock can only guarantee approximate time interval, but not necessarily accurate, may appear set interval is 30 minutes, but actually one interval 20 minutes, another interval 40 minutes. Its biggest advantage is that it can combine alarm events, for example, interval settings every 30 minutes, do not wake up hibernation, 8 hours after the sleep has accumulated 16 alarm events, and when the phone is awakened, the clock can be not on time to merge 16 events into one, so it seems that the clock is not on time in general more energy saving.

formatter.formatfilesize () a regionalization file size format tool. In layman's terms, the size is converted to a string such as mb,g,kb.

actionbar.hide ()/.show () hides and displays Actionbar, which can be gracefully converted between Full-screen and band Actionbar.

linkify.addlinks () adds a link to the text. Very practical.

Staticlayout is useful when rendering text in custom View.

activity.onbackpressed () is a convenient way to manage the back key, sometimes you need to control the return key events, you can rewrite. For example, add the "point two back key exit" function.

gesturedetector used to monitor and correspond to the corresponding gesture events, such as clicks, long press, slow sliding, fast sliding, easy to use, than your own implementation is much more convenient.

Drawfilter allows you to manipulate canvas without invoking the Ondrew method, and you can set up a drawfilterwhen creating a custom view that gives all view in the parent view Sets the anti alias.

Activitymanager.getmemoryclass () tells you how much memory your machine has, which is useful when calculating the cache size.

Viewstub It is an initialization View that does nothing, but can then load a layout file. It's a good place to do placeholders in slow load View. The only downside is that you don't support tags, so if you're not careful, you might want to add unwanted nesting to the view structure.

systemclock.sleep () This method is convenient when it comes to sleep for a certain amount of time, and is usually used for debug and analog network latency.

displaymetrics.density This method you can get device pixel density, most of the time it is best to allow the system to automatically scale resources such as operations, but sometimes the effect of control is better. (especially when customizing view).

pair.create () is a convenient way to build classes and constructors.

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.