What are the methods, classes, or interfaces that make you feel brief encounter in Android development?

Source: Internet
Author: User

1. In the Throwable classgetstacktrace ()method, according to this method can get the function of the layer-by-call address, its return value is stacktraceelement[];

2.stacktraceelementClass, where four methods GetClassName (), GetFileName (), Getlinenumber (), getmethodname () are useful when the debugger prints log;

3.Uncaughtexceptionhandlerinterface, a good code exception is unavoidable, using this interface can handle the uncaught exception;
Use See: Android uses Uncaughtexceptionhandler to catch global exceptions

4. In the Resources categorygetidentifier (name, Deftype, Defpackage)method, obtains its ID according to the resource name, often uses when doing the UI;

5. In viewIsshown ()method, used to be judged by view.getvisibility () = = View.visible (╯-╰);

6. In the Arrays classaslist (T ... array)method, array to list collection, and vice versa list.ToArray ()

7, the Android.text.format.Formatter classformatfilesize (Context, long)Method used to format the file size (B→KB→MB→GB);

8.android.media.ThumbnailUtilsClass for obtaining thumbnails of media (Pictures, videos);

9. In the String classformat (String, Object ...)method, which is used to format the string in the Strings.xml (thanks @droider an hint: GetString in the context class (int, Object ...) Method is more convenient to use);

10. Three methods in the view class:Callonclick ()PerformClick ()Performlongclick (), which is used to trigger the view's Click event;

11. In the Textutils classisEmpty (String)method to determine whether the string is null or "";

12. In the TextView classAppend (String)method, add text;

13. In the View classGetdrawingcache ()And so a series of methods, currently only know can be used;

14.DecimalFormatclass, used for string formatting including the specified number of bits, percentages, scientific notation, etc.;

15. In the System classarraycopy (SRC, Srcpos, dest, Destpos,length)method, used to copy the array;

16. In the Fragment classonhiddenchanged (Boolean)method, using Hide () in Fragmenttransaction, show () fragment other life-cycle methods will not be called, too pit Dad!

17. Activity Classonwindowfocuschanged (Boolean)Method

18. In the View classGetlocationinwindow (int[])Methods andGetlocationonscreen (int[])method to get the position of the view in the window/screen;

19. In the TextView classSettransformationmethod (Transformationmethod)method, can be used to implement the "Display password" function;

20.TextwatcherInterface to listen for changes in the contents of the text input box;

21. In the View classsetselected (Boolean)Method combined with android:state_selected= "" To achieve the picture selection effect;

22. Surface Settings Transparent:Surfaceview.setzorderontop (TRUE);
Surfaceview.getholder (). SetFormat (pixelformat.translucent);
But it will block other controls;

23. In the ListView or GridView Classsetfastscrollenabled (Boolean)method to set whether the Quick scroll slider is visible, of course, if the item is sufficient;

24.Pagetransformerinterface, using the Viewpager page to switch animations using theSetpagetransformer (Boolean, Pagetransformer)method to set up;

25. Apache offers a range of jar packages:Commons-lang.jarCommons-collections.jarCommons-beanutils.jarAnd so on, there are a lot of ways that you might have done with a few hundred lines of code, but the execution efficiency may be much worse, such as: Arrayutils,stringutils ... ;

26.Androidtestcaseclass, Android unit test;

27. Activity Classonnewintent (Intent)Method.

1, GetParent (). Requestdisallowintercepttouchevent (true); deprive the parent view of the right to touch events, who knows who.

2, argbevaluator.evaluate (float fraction, object Startvalue, Object Endvalue), used to generate a new color based on a starting color value and an end color value, and an offset. The minute implementation is similar to the bottom bar of sliding color gradients.

3. API for Cliprect, Clippath, and clipregion clipping regions in canvas.

4, Bitmap.extractalpha (); Returns the alpha value of a new bitmap,capture original image. Sometimes we need to dynamically modify the background image of an element and do not want to use more than one picture, through this method, combined with canvas and paint can dynamically modify a solid color bitmap color.

5, Handlerthread, instead of constantly new thread of the repeated physical writing threads.

6. Intentservice, a service that can go to die and not need us to manage the child thread after the job is done.

7, palette,5.0 can be added to extract a bitmap in the color of the class, combined with the above Bitmap.extractalpha, you understand.

8, executors.Newsinglethreadexecutor(); This is Java, and before it was known, it took a lot of effort to study the single-threaded sequential execution of the task queue.

9. Android:animatelayoutchanges= "True", the method of adding view animation in LinearLayout, supports custom animation through Setlayouttransition ().

10, Viewdraghelper, custom viewgroup handling various events very tired, eh? What the fuck!!

11, Gradientdrawable, before taking over the company's project, found a shadow effect is also good, thought is cut pictures, a look at the code, what ghost = =!

12, Asyncqueryhandler, if you do the development of system tools, such as contact SMS AIDS, and so on, certainly inevitably and contentprovider deal with, if the amount of data is not very large, casually engage, if the volume of data large case, It is necessary to understand this class, and it is important to note that this thing eats abnormally.

13, Viewflipper, to achieve a plurality of view switching (looping), can customize the animation effect, and can be specified for a single switch animation.

14, a friend mentioned in the custom view some methods when the hardware acceleration is not effective when the problem, after API16 there are many methods do not support hardware acceleration, usually we turn off hardware acceleration is in the manifest file through <application android: Hardwareaccelerated= "false" ...; in fact, Android also provides a way to turn off hardware acceleration for a particular View, calling View.setlayertype (View.layer_type_software , null);

15, the pair class in the Android util package, can be conveniently used to store a "group" of data. Note that it is not key value.

16, Pointf,graphics package in a class, we often see in the processing of touch events when the definition of a downx, a downy used to store a coordinate, if the coordinates are not good, if you want to record too much of the coordinates of the code is bad to see. Using pointf (float x, float y) to describe a coordinate point is much clearer.

17, Statelistdrawable, the definition of selector the usual way is the XML file, but sometimes our image resources may be dynamically obtained from the server, such as many apps so-called skin, this time can only pass statelistdrawable
To complete, a variety of addstate can be.

18, Android:descendantfocusability,listview the item in the checkbox and other elements of the grab focus causes the item Click event can not respond, in addition to the corresponding element set focusable, More simply, add android:descendantfocusability= "Blocksdescendants" to the item root layout

19,Android:duplicateparentstate= "true" to let the child view follow the state of its parent, such as pressed. A common usage scenario is when a button is small, and we want to expand the area of the click to give it a layer of layout, write the Click event to the parent, and if you want the selector of the click Effect of the Parcel button to continue to take effect, This is where Duplicateparentstate comes in handy.

20, includefontpadding= "false", textview default up and down is a certain padding, sometimes we may not need to leave the upper and lower part of the white, plus it can.

21, Messenger, interview usually will be asked to communicate between the process, under normal circumstances everyone is beginning to endorse, Aidl Balabala. One day on the blog of Hung god see this, well, as he said, can also be installed.

22, Textview.seterror (); Used to validate user input.

23, Viewconfiguration.getscaledtouchslop (), the minimum distance to trigger the move event, when customizing the View processing touch event, sometimes it is necessary to determine whether the user really exists in the movie, the system provides such a method.

24, Valueanimator.reverse (); Smooth cancellation of animation effects.

25, Viewstub, sometimes a region needs to show a different layout according to the situation, usually we will show and hide different layouts by setvisibility method, but this default is all loaded, with viewstub can better improve performance.

26, Ontrimmemory, in the activity to override this method, will be in memory tense when the callback (support multiple levels), to facilitate our active resource release, to avoid oom.

urlquerysanitizer--Use this tool to make it easy to check URLs.

fragment.setarguments--because it is not possible to add parameters when building a Fragment, this is a good thing to set parameters (even when the configuration changes) before creating the Fragment.

Dialogfragment.setshowsdialog ()--This is a very ingenious way, dialogfragment can be displayed as normal Fragment! This allows Fragment to take on dual tasks. I usually add oncreateview () and ONCREATEDIALO.G () when I create a Fragment to create a Fragment with a dual purpose.

Fragmentmanager.enabledebuglogging ()--it helps when you need to observe the Fragment state.

localbroadcastmanager--This will be safer, simpler and faster than the overall broadcast. The Event buses mechanism such as Otto is more useful for your application scenario.

Phonenumberutils.formatnumber ()-As the name implies, this is used when the numbers are formatted.

Region.op ()--I found it useful to compare the area before two renderings, and if you have two paths, how do you know if they overlap? Use this method to do so.

application.registeractivitylifecyclecallbacks--Although the official documentation is missing, I think it is a handy tool for registering the Activity's life cycle with some callback methods (as the name implies).

versionnamesuffix--This gradle setting allows you to modify the version Name property in manifest based on different build types, for example, if you need to end with "-snapshot" in the debug version, you can easily see that the current Debug version or Release version.

cursorjoiner--If you are using only one database, you can use join in SQL, but Cursorjoiner is useful if you receive data from two independent contentprovider.

genymotion--a very fast Android simulator that I have been using.

-nodpi--in the absence of a special definition, many modifiers (-mdpi,-hdpi,-xdpi, and so on) will automatically scale assets/dimensions by default, and sometimes we need to keep the display consistent, in which case we can use-nodpi.

Broadcastrecevier.setdebugunregister ()--Another convenient debugging tool.

Activity.recreate ()--forces the Activity to rebuild.

Packagemanager.checksignatures ()-If you have installed two apps at the same time, you can use this method to check. Without a signature check, other people can easily imitate your app by using the same package name.


Activity.ischangingconfigurations ()-If the configuration changes frequently in the Activity, you can use this method without having to manually save the state of the work.

searchrecentsuggestionsprovider--is a quick and easy way to create the provider of the most recent cue effect.

viewtreeobserver--This is a great tool. You can enter into the view and monitor various states of the view structure, which I usually use to do the view measurement (often used in custom views).

org.gradle.daemon=true--This sentence can help reduce the time of gradle build, only when the command line is compiled, because Android Studio has already used this.

databaseutils--a usage tool that contains various database operations.

Android:weightsum (linearlayout)-if you want to use layout weights, but do not want to fill the entire linearlayout, you can use WeightSum to define the total weight size.

Android:duplicateparentstate (view)-This method allows the child view to replicate the state of the parent view. For example, if a viewgroup is clickable, you can use this method to change the state of its sub-View when it is clicked.

Android:clipchildren (ViewGroup)--If this property is set to unavailable, then ViewGroup's child View will be drawn out of its range, which is required when animating.

Android:fillviewport (ScrollView)--In this article is a detailed article link, you can solve in ScrollView when the content is not enough to fill the screen when the problem.

Android:tilemode (bitmapdrawable)--You can specify the pattern in which the picture uses a repeating fill.

Android:enterfadeduration/android:exitfadeduration (Drawables)--this property can define the fade effect before it is displayed when the drawable has multiple states.

Android:scaletype (ImageView)--Define how to scale/crop the picture in ImageView, generally use more "Centercrop" and "Centerinside".

merge--This tag can include other layout files in another layout file, instead of creating a new viewgroup, which is required for custom viewgroup, you can automatically define its subassemblies by loading a tabbed layout file.

atomicfile--atomically through the use of backup files. I have written this point before, but it is better to have an official version.


viewdraghelper--View dragging is a more complex issue. This class can help solve a lot of problems. If you need an example, drawerlayout is using it to make the sweep slip. Flavient Laurent also wrote some excellent articles on this.

Popupwindow--android everywhere using Popupwindow, even you do not realize (title navigation bar Actionbar, auto-complete AutoComplete, edit box Error alert EditText Errors). This class is the primary method for creating floating-layer content.

Actionbar.getthemrcontext ()-the theme of the navigation bar is complex (different from the theme of other parts of the activity). You can get a context, and a custom component created with this context can get the correct theme.

thumbnailutils--help create thumbnails. Usually I load libraries with existing images (for example, Picasso or volley), but this thumbnaiutils can create video thumbnails. Translator Note: This API is only supported from V8.

Context.getexternalfilesdir () ———— after applying for SD card Write permission, you can write data anywhere in SD, and it will be more polite to write your data in the right place. This data can be cleaned up in time, and there will be a better user experience. In addition, the Android 4.0 KitKat in this folder to write data is not required permission, each user has their own independent data storage path. Translator Note: This API is only supported from V8.

Efficient and optimized version of the Sparsearray--map. It is recommended to learn about sister Sparsebooleanarray, Sparseintarray and Sparselongarray.

Packagemanager.setcomponentenabledsetting ()--can be used to start or disable components in the program manifest. It is great to turn off unwanted functional components, such as turning off a broadcast receiver that is not currently in use.

Sqlitedatabase.yieldifcontendedsafely ()--lets you temporarily stop a database transaction so that you can not consume too much system resources.

Environment.getexternalstoragepublicdirectory ()-or that sentence, users expect a unified user experience on the SD card. Use this method to get the correct directory for placing the specified type of file (music, pictures, etc.) on the user's device.

View.generateviewid ()--every time I want to recommend the ID of a dynamically generated control. It is important to note that you do not duplicate the existing control ID or other control IDs that have already been generated.

Activitymanager.clearapplicationuserdata ()--One click to clean up the user data generated by your app may be the easiest way to do the user exit login feature ever.

Context.createconfigurationcontext ()--Customize your configuration environment information. I usually get the problem of forcing a part to appear in a particular environment (not that I've been so blind, long story, you're hard to understand). This can be a little bit simpler to implement.

The activityoptions--facilitates the definition of two activity toggle animations. Using Activityoptionscompat can be a good solution to older versions of compatibility issues.

ADAPTERVIEWFLIPPER.FYIWILLBEADVANCEDBYHOSTKTHX ()--just because it's fun, there's no other reason. There are other interesting things in the entire Android Open source project (AOSP the Android--pen source project Android Open source program) (e.g.
Gravity_death_star_i). But it's not like this, it really works.

Viewparent.requestdisallowintercepttouchevent ()--android system touch event mechanism can be handled by default most of the time, but sometimes you need to use this method to deprive the parent control of control (by the way, If you want to learn more about the Android touch mechanism, this speech will amaze you. )

Activity.ischangingconfigurations ()-If the configuration changes frequently in the activity, you can use this method without having to manually save the state of the work.

searchrecentsuggestionsprovider--is a quick and easy way to create the provider of the most recent cue effect.

viewtreeobserver--This is a great tool. You can enter into the view and monitor various states of the view structure, which I usually use to do the view measurement (often used in custom views).

org.gradle.daemon=true--This sentence can help reduce the time of gradle build, only when the command line is compiled, because Android studio has already used this.

databaseutils--a usage tool that contains various database operations.

Android:weightsum (linearlayout)-if you want to use layout weights, but do not want to fill the entire linearlayout, you can use WeightSum to define the total weight size.

Android:duplicateparentstate (view)-This method allows the child view to replicate the state of the parent view. For example, if a viewgroup is clickable, you can use this method to change the state of its sub-view when it is clicked.

Android:clipchildren (ViewGroup)--If this property is set to unavailable, then ViewGroup's child view will be drawn out of its range, which is required when animating.

Android:fillviewport (ScrollView)--In this article is a detailed article link, you can solve in ScrollView when the content is not enough to fill the screen when the problem.

Android:tilemode (bitmapdrawable)--You can specify the pattern in which the picture uses a repeating fill.

Android:enterfadeduration/android:exitfadeduration (Drawables)--this property can define the fade effect before it is displayed when the drawable has multiple states.

Android:scaletype (ImageView)--Define how to scale/crop the picture in ImageView, generally use more "Centercrop" and "Centerinside".

<merge>--This tag can include other layout files in another layout file, instead of creating a new viewgroup, which is required for custom viewgroup, you can automatically define its subassemblies by loading a tabbed layout file.

atomicfile--atomically through the use of backup files. I have written this point before, but it is better to have an official version.



-----------------------------------------------------------------------------------------------

The translation is too much to know where, and some are not, the original from Dan Lew blog, there are 5, strongly recommended.

Android Tips round-up, part 1
Android Tips round-up, part 2
Android Tips round-up, Part 3
Android Tips round-up, Part 4
Android Tips round-up, Part 5

Finally make a welfare ad zhengxiaopeng/android-dev-bookmarks GitHub

What are the methods, classes, or interfaces that make you feel brief encounter in Android development?

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.