As a porter of the Android world, every day to move bricks is hard enough to get tired, walking in the bumpy road accidentally fell into the pit.
SDK Common tool Classes
The Android SDK itself has a lot of wheels and is familiar with these wheels, which can improve our efficiency of moving bricks.
Android.text.TextUtils
Common methods for string manipulation:isEmpty () ,join (),split () , etc.
if (! textutils.isempty (text)) { //dosomething}
Android.webkit.URLUtil
Links related to common methods:Ishttpurl (),Isnetworkurl (),decode ( ), etc.
android.util.Patterns or android.support.v4.util.PatternsCompat
This class defines a number of common regular expression constants that can be used directly, for example: IP address ip_address, url web_url, email address email_address, telephone PHONE.
With it, my mother no longer has to worry about my regular expression problem.
Matcher Urlmatcher = Patterns.WEB_URL.matcher (text); if (Urlmatcher.find ()) { //find URL}
Android.telephony.PhoneNumberUtils
Phone-related tool classes
Android.text.format.Formatter
The format file size, in GB,MB,KB.
Android.media.ThumbnailUtils
Create a picture or video thumbnail
Common methods:createimagethumbnail (),createvideothumbnail ()
Android.database.DatabaseUtils
Database Operations related Tools classes
?
The Common pit
The following experience is a small note of an accident occurring when AC is driving. One of the solutions, by the Yu Yu car environment differences and AC i limited capacity, you old drivers can refer to as appropriate, but also welcome the old driver comments pointed out.
Handler handles asynchronous operations by isFinishing()
Judging whether the current activity exists: for example, after the network request data callback back, in the handler handleMessage()
method,
isFinishing()
Determine whether the current activity exists, or it is very easy to appear null pointers and other exceptions.
Set footer in Listfragment, not in the onCreateView()
settings; onActivityCreate()
Caused by: java.lang.IllegalStateException: Content view not yet created
If the style on the page appears strangely rendered (a flower screen, flashing, and so on), see if the activity or view is adding hardware acceleration.
The Setcustomanimations method is not valid until the method is Replace,remove, and so on.
Fragmenttransaction ft = getsupportfragmentmanager (). BeginTransaction (); 0); Ft.replace (r.id.frame_content,mfragment);
Get the height and width of the view in the OnCreate, call directly View.getHeight()
or View.getWidth()
, get 0. The height or width of the view should be obtained using the following methods.
Mview.post ((),{ log.d("width:" +mview.getwidth () + ", Height:" +mview.getwidth ());});
Activitya by startActivityForResult()
launching the activityb. If Activityb's Launchmode is Singletop or Singletask, the Activitya onActivityResult(int requestCode,int resultCode,Intent data)
method ResultCode must be Activity.result_ CANCELED.
At startActivity
the time of the flash back and the following log appears:
- Java.lang.SecurityException:Unable to find app for caller Android.app.ApplicationThreadProxy. This log means the your app is having trouble handling a communication intent. Sometimes problems like this can is cause by sending a intent with big extras. Try to reduce the dimension of the image or, and the "The best", save your image on the SD and put in the extras onl Y the Uri of that image.
- Android.os.TransactionTooLargeException
Note: Do not pass a large amount of data (such as list, large picture, etc.) in intent, otherwise you will throw an exception.
Drawable in the selector file if you use android:exitFadeDuration="@android:integer/config_shortAnimTime"
this property, then different phones may have different effects, use with caution!!
In the implementation of WebView and JS Interactive process, if encountered after the Click JS method is not responding, you should pay attention to the problem: (1) webview.addjavascriptinterface (new Androidclick (), "Android"); The alias of this method is whether Android is consistent with the object name in JS, such as (2) WebView need to implement the registration of this callback function.
Webview.setwebchromeclient (new webchromeclient () { @Override public Boolean Onjsalert (WebView view, string URL, string message, jsresult result) { return Super. Onjsalert (view, URL, message, result); });
(3) If the published app has been confused, then androidclick this JS and Java interaction class needs proguard.cfg file ignore this class confusion, otherwise confusing JS will not execute.
class net.angrycode.js2java.androidclick{ *;}
TextView implements simple graphics and text, you can use properties such as TextView's drawabletop to set up the picture on the page, and you can set the picture with Imagespan.
Alertdialog Press the OK button does not disappear method
Alertdialog dialog = builder.create (); Dialog.setcanceledontouchoutside (true); Dialog.show (); { = edittext.gettext (). toString (). Trim (); if (Textutils.isempty (text)) { Toastutils.showtoast (this, r.string.say_something); return; } // The Execution dialog box disappears here . Dialog.dismiss (); });
Follow us to get more
Android old driver moves bricks tips