public void startActivities (Intent[] intents)
- 该方法和我们平常用到的startActivity非常相似,只不过将Intent[]中的Intent所指向的跳转目标Activity从后往前依次添加到返回栈中。跳转完后如果按Back键的话会发现返回的顺序和Intent[]中的顺序前后一致。
Same as startActivities(Intent[], Bundle) with no options specified.
public static boolean isEmpty (CharSequence str)
- 我经常在项目中使用,判断字符创是否为空或是否为null非常方便。
Returns true if the string is null or 0-length.
public static Spanned fromHtml (String source)
- 一个很方便格式化Html代码的方法,但因为处理速度不太快,所以我不太经常用它。不建议用该方法处理String样式,通常建议使用Spannable来处理。
Returns displayable styled text from the provided HTML string. Any <img> tags in the HTML will display as a generic replacement image which your program can then Go through and replace with real images.
This uses TagSoup to handle real HTML, including all of the brokenness found in the wild.
public void setError (CharSequence error)
- 在TextView上不太常用,更多用在EditText上(EditText继承自TextView)提示用户输入非法。还有个多态方法setError(CharSequence error,Drawable icon)来让开发者自定义错误提示图片。
Sets the right-hand compound drawable of the TextView to the "error" icon and sets an error message that will be displayed in a popup when the TextView has focus. The icon and error message will be reset to null when any key events cause changes to the TextView's text. If the error is null, the error message and icon will be cleared.
public static String getStackTraceString (Throwable tr)
- 有时候我们希望程序抛出异常时能把异常信息保存到制定目录的文件中,getStackTraceString就可以将异常信息转换成字符串的形式。
Handy function to get a loggable stack trace from a Throwable
public static LayoutInflater from (Context context)
- 和冗长的getSystemService()说Goodbye。
Obtains the LayoutInflater from the given context.
public abstract File getCacheDir ()
- 获取应用默认缓存路径“/data/data/应用包名/cache”
Returns the absolute path to the application specific cache directory on the filesystem. These files will be ones that get deleted first when the device runs low on storage. There is no guarantee when these files will be deleted. Note: you should not rely on the system deleting these files for you; you should always have a reasonable maximum, such as 1 MB, for the amount of space you consume with cache files, and prune those files when exceeding that space.
public void reverse ()
- 因为当调用这个方法时,如果动画正在播放,可以反向播放动画直到回播放的原点。所以我喜欢用它来平滑的结束动画的播放。
Plays the ValueAnimator in reverse. If the animation is already running, it will stop itself and play backwards from the point reached when reverse was called. If the animation is not currently running, then it will start from the end and play backwards. This behavior is only set for the current animation; future playing of the animation will use the default behavior of playing forward.
本文介绍了多个实用的Android开发技巧,包括使用startActivities方法批量启动活动并控制返回顺序、检查字符串是否为空、处理HTML文本、设置错误提示、获取异常堆栈信息、简化布局加载、获取应用缓存目录以及反向播放动画等。
2071

被折叠的 条评论
为什么被折叠?



