Android development tips set

Classification: Andrews learning 158 people read Comment(0) Collection Report

Original text:

Recent projects I have every day: a about Android classes and methods tips, many readers asked to sort out these tips archive links, so every few weeks I will summarize. If work is not too busy, I will make some notes on it.

The development of Android (Part 1~4) a collection of tips

        Android development tips set (1)

        Activity.startActivities ()- for the The middle of the app flow is very good.

        TextUtils.isEmpty ()- a simple tool for general application.

        Html.fromHtml ()- fast way to format Html, I think it is not very fast, so I do not often use it (I say it is not often used in order to focus on this sentence: please build Spannable to replace Html.fromHtml), but it is very good for rendering text from the web.

        TextView.setError ()- user experience is very good in validating user input.

        Build.VERSION_CODES- it not only describes the version number, but also summarizes the different characteristics of the Android versions.

        Log.getStackTraceString ()- convenient logging tool.

        LayoutInflater.from ()- simplify a series of lengthy getSystemService () a simple tool called.

        ViewConfiguration.getScaledTouchSlop ()- use The values provided in the ViewConfiguration to ensure that all the touch of the interaction is unified.

        PhoneNumberUtils.convertKeypadLettersToDigitsThe number is more convenient to handle, a lot of people only offer letters, not numbers.

        Context.getCacheDir ()Using the system provided by the cache directory data cache, operation is very simple, but a lot of people do not know how to use.

        ArgbEvaluators- processing of color gradient. Just likeChris BanesThe same, this kind of will carry out a lot of automatic packing operation, so it is best to remove the logic of its own to achieve it.

        ContextThemeWrapper- easy to change the theme in the running process.

        Space-- lightweight components of a view can skip rendering process, for any scene need placeholders are great.

        ValueAnimator.reverse ()- you can smooth the animation effect, very good.

The development of Android (Part 1~4) a collection of tips

        Android development tips set (2)

        DateUtils.formatDateTime ()- a one-stop service to provide a regional format time / date string.

        AlarmManager.setInexactRepeatingThrough the way of grouping the alarm -- save power, even if you only call a Alarm instance, it is still relatively easy to use (it can be sure that the automatic call AlarmManager.cancel () at the end of the use.

        Formatter.formatFileSize ()- a regional file size format tool.

        ActionBar.hide ()/.show ()- you can display or hide the actionBar display or hide. You can be more elegant when you switch to full screen.

        Linkify.addLinks ()- can be controlled in Text Add link.

        StaticLayout- practical application of rendering text in a custom View.

        Activity.onBackPressed ()- easy to control the return button, the need to customize the return key to the operation, you can use.

        GestureDetectorYou can monitor the action -- events and the associated event listener (click, scroll, slide etc.). Some action events are more simple than their own system.

        DrawFilter- you can let you operate Canvas, even if you do not call the draw method. For example, you can set up a DrawFilter, to the father when you create a custom View View inside the View set the anti alias.

        ActivityManager.getMemoryClass ()- you know how much memory is left in the device. When calculating how to set the cache size, it will be useful.

        SystemClock.sleep ()- this method is convenient for a certain time of sleep, and is usually used for debug And simulated network delay.

        ViewStub- it's an View that does not do anything, but after that, you can load a layout file. In the slow loading View is suitable for the placeholder. The only drawback is that you don't support the label, so if you're not careful, you might want to add a no need to the view structure.

        DisplayMetrics.densityBy this method, the density of the screen can be obtained, and a lot of time is required to remove the function of the system's automatic scaling function, but sometimes it is useful to control the time (especially in custom View time).

        Pair.create ()The construction method is convenient -- class and constructor.

The development of Android (Part 1~4) a collection of tips

        Android development tips set (3)

        UrlQuerySanitizer- using this tool to check the URL.

        Fragment.setArgumentsBecause the Fragment can not be added when the parameters, so it is a very good thing, you can create Fragment before setting the parameters (even when the configuration is changed, it will result in the destruction / reconstruction).

        DialogFragment.setShowsDialog ()- this is a very clever way, DialogFragment Can be displayed as normal Fragment! Fragment can take a double task here. I usually add the onCreateView () and onCreateDialog () to create a Fragment with a dual purpose Fragment.

        FragmentManager.enableDebugLogging ()- in need of observation Fragment status will help.

        LocalBroadcastManager- this will be more secure, simple and fast than the global broadcast. LikeOttoSuch Buses Event mechanism is more useful for your application.

        PhoneNumberUtils.formatNumber ()- as the name suggests, this is the time to use the format of the number for the operation.

        Region.op ()- I found it very useful to compare the area before the two rendering. If you have two paths, how do you know if they are going to be? Using this method can be done.

        Application.registerActivityLifecycleCallbacks- although the official document is missing, I think it's a sign. Activity's life cycle of some callback methods (Gu Mingsiyi), is a convenient tool.

        VersionNameSuffix- this gradle setting allows you to modify the version name in the manifest of different build types, for example, if you need to. Debug version of the "-SNAPSHOT" end, so you can easily see the current is the debug version or release version.

        CursorJoinerIf you are using only one database, the join in SQL can be used, but if the data you receive is from two separate ContentProvider CursorJoiner is very practical.

        Genymotion- a very fast Android simulator, I have been using.

        -nodpi- in no particular definition, many modifiers (-mdpi, -hdpi, -xdpi etc.) will default automatic scaling assets/dimensions sometimes we need keep consistent with that, this case can be used -nodpi.

        BroadcastRecevier.setDebugUnregister ()- another convenient debugging tool.

        Activity.recreate ()Forced Activity reconstruction.

        PackageManager.checkSignatures ()- if you have two app at the same time, you can use this method to check. If you do not sign inspection, other people can easily use the same package names to imitate your app.

The development of Android (Part 1~4) a collection of tips

        Android development tips set (4)

        Activity.isChangingConfigurations ()- if you are in Activity Configuration will often change, the use of this method can not do the work of the state of the manual.

        SearchRecentSuggestionsProvider- provider, which is a simple and quick way to create a that has recently prompted a result.

        ViewTreeObserver- this is a great tool. You can enter into the VIew, and monitor the View structure of the various states, usually I used to do View Measurement operation (often used in custom views).

        Org.gradle.daemon=trueThis sentence can help reduce the time for Gradle construction, only when the command line is compiled, because Studio Android has been used.

        DatabaseUtils- a tool that contains all kinds of database operations.

        Android:weightSum (LinearLayout)- if you want to use layout Weights, but you do not want to fill the entire LinearLayout, you can use weightSum to define the total weight size.

        Android:duplicateParentState (View)- this method can make the son View can replicate the state of the parent View. For example, if a ViewGroup is available, the method can be used to make the View change the state when it is clicked.

        Android:clipChildren (ViewGroup)- if this property is not available, then ViewGroup child View in the time of rendering will be beyond the scope of it, the need to use the time to do the animation.

        Android:fillViewport (ScrollView)-- a detailed introduction in this articleArticle linkAnd can be settled in ScrollView when the content is insufficient to fill the screen of the problem.

        Android:tileMode (BitmapDrawable)- you can specify the image to use a repeat fill mode.

        Android:enterFadeDuration/android:exitFadeDuration (Drawables)- this property is in When Drawable has multiple conditions, it can be defined before the show fades.

        Android:scaleType (ImageView)- definition of how to zoom in the ImageView and the image, the general use of the more is the "centerCrop" and "centerInside".

        - this tag can also include other layout files in another layout file, instead of creating a new ViewGroup, for custom ViewGroup It also needs to be used; the sub component can be automatically defined by loading a layout file with a label.

        AtomicFile- atomic operation of a file using a backup file. I have written before this knowledge point, but it's better to have an official version of it.

Original link:DanlewTranslation:Bole Online-Chris


Guess what you're looking for.
View comments
* above the user's comments only represent their personal views, do not represent the views or position of the CSDN website
    Personal data
    • Visit36136 times
    • Integral:1740
    • Grade
    • Rank:13015th
    • Original144
    • Reprint:36
    • Translation:1
    • Comment:9
    Latest comments