Current location - Recipe Complete Network - Complete cookbook of home-style dishes - There are several principles for android to implement interfaces.
There are several principles for android to implement interfaces.
1, the getStackTrace () method in the Throwable interface (or the getStackTrace () method of the Thread class), according to which the layer-by-layer calling address of the function can be obtained, and the return value is stacktraceelement [];

2.StackTraceElement class, in which four methods getClassName (), getFileName (), getLineNumber () and getMethodName () are very useful when debugging programs to print logs;

3.UncaughtExceptionHandler interface, even the best code exceptions are inevitable, and this interface can be used to clean up uncaught exceptions;

Use see: Android uses UncaughtExceptionHandler to catch global exceptions.

4. The getIdentifier (name, deftype, defpackage) method in the 4.Resources class obtains its ID according to the resource name, which is often used in the UI.

5. The isShown () method in the view was previously judged by the view. GetVisibility () = = view. Visible (╯□╰); (Thanks for reminding me, there is actually a pit in it: the usage of androidview.isShown ())

6. A series of tools and methods about array operation in 6.Arrays class: binarySearch (), asList (), equals (), sort (), toString (), copyOfRange (), etc.

A series of tools and methods about collection operation in Collections class: sort (), reverse (), etc.

7. The formatFileSize(Context, long) method in the android.text.format.formatter class is used to format the file size (B → KB → MB → GB);

8.android.media.ThumbnailUtils class, used to obtain media (pictures, videos) thumbnails;

9. Format (string, object ...) method is used to format strings in strings.xml (thanks to the tip of @droider An: the method in getString(int, Object...)Context class is more convenient to use);

10, three methods in the view class: callOnClick (), performClick () and performLongClick (), which are used to trigger the Click event of the view;

1 1, isEmpty(CharSequence) method in TextUtils class, to judge whether the string is null or "";

12, append(CharSequence) method in TextView class, add text. Some special words directly connected with+will become strings; ;

A series of methods such as 13 and getDrawingCache () in the View class are only known for screenshots.

14, DecimalFormat class, used for string formatting, including specifying numbers, percentages, scientific counting methods, etc.

The ArrayCopy (src, srcpos, dest, destpos, length) method in 15.System class is used to copy arrays;

16, the onHiddenChanged(boolean) method in Fragment class, when using hide () and show () in FragmentTransaction, it seems that other life cycle methods of the fragment will not be called. What a pity!

Callback methods such as 17, onWindowFocusChanged(boolean), onNewIntent(intent) in the Activity class;

18, the getLocationInWindow(int[]) method and getlocationscreen(int[]) method in the view class get the position of the view in the window/screen;

19. You can use the SettransFormationMethod in TextView class to realize the function of "displaying password";

20.TextWatcher interface, which is used to monitor the changes of the contents of the text input box and can be used to realize a series of text input boxes with special functions;

2 1, the setSelected(boolean) method in View class is combined with android:state_selected= ""to achieve the effect of picture selection;

22. the 22.Surface setting is transparent: surfaceview.setzordontop (true);

SurfaceView.getHolder()。 setFormat(PixelFormat。 Translucent); But it will block other controls;

23. the setFastScrollEnabled(boolean) method in the 23.ListView or GridView class is used to set whether the fast scroll slider is visible, provided that there are enough items;

24.PageTransformer interface, which is used to customize the page switching animation of ViewPager and set by the method of SetPageTransformer (Boolean, PageTransformer);

25. A series of jar packages provided by Apache: commons-lang.jar, commons-collections.jar, commons-beanutils.jar, etc. Many of them may have been implemented with dozens or hundreds of lines of code, but the execution efficiency may be much worse, such as: ArrayUtils, string utils……;; ...;

26, AndroidTestCase class, androidunit test, which is very convenient to use in AndroidStudio;

27. setKeyListener(KeyListener) method of TextView class;

Among them, the DigitsKeyListener class can specify an editable text input character set by using the getInstance(String accepted) method;

28.ActivityLifecycleCallbacks interface, which is used to monitor the state change of each activity in the application class;

29. The createpackagecontext (packagename, flags) method in the context class can be used to obtain the context object of the application with the specified package name.