转自:http://blog.danlew.net/2014/04/28/android-tips-round-up-part-3/

Here's the third round-up of Android tips I've been posting.

More:Part 1|Part 2| Part 3 |Part 4|Part 5

UrlQuerySanitizer- Sanitize URLs with this handy utility.

Fragment.setArguments- Since you can't use a Fragment constructor w/ parameters this is the second best thing. Arguments set before creation last throughout the entire Fragment's lifecycle (even if it's destroyed/recreated due to a configuration change).

DialogFragment.setShowsDialog()- Neat trick - DialogFragments can act like normal Fragments! That way you can have the same Fragment do double-duty. I usually create a third View generation method that bothonCreateView()andonCreateDialog()call into when creating a dual-purpose Fragment.

FragmentManager.enableDebugLogging()- Help when you need it when figuring out Fragments.

LocalBroadcastManager- Safer than global broadcasts. Simple and quick. Event buses likeottomay make more sense for your use case though.

PhoneNumberUtils.formatNumber()- Let someone else figure out this problem for you.

Region.op()- I found this useful for comparing two generic areas before rendering. If I've got two Paths, do they overlap? I can figure that out with this method.

Application.registerActivityLifecycleCallbacks- Though lacking documentation I feel this is self-evident. Just a handy tool.

versionNameSuffix- This gradle setting lets you modify the versionName field in your manifest based on different build types. For example, I would setup my debug build type to end in "-SNAPSHOT"; that way you can easily tell if you're on a debug build or release build.

CursorJoiner- If you're using a single database then a join in SQL is the natural solution, but what if you've received data from two separate ContentProviders? In that case CursorJoiner can be helpful.

Genymotion- A much faster Android emulator. I use it all day.

-nodpi- Most qualifiers (-mdpi, -hdpi, -xhdpi, etc.) automatically scale assets/dimensions if you're on a device that isn't explicitly defined. Sometimes you just want something consistent though; in that case use -nodpi.

BroadcastRecevier.setDebugUnregister()- Another handy debugging tool.

Activity.recreate()- Forces an Activity to recreate itself for whatever reason.

PackageManager.checkSignatures()- You can use this to find out if two apps (presumably your own) are installed at the same time. Without checking signatures someone could imitate your app easily by just using the same package name.


更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Demo:选择屏幕写页签
  2. OO ALV常用功能完整简例(热键单击,双击,帮
  3. SAP盘点:创建盘点凭证BAPI_MATPHYSINV_CRE
  4. SE75 采购申请创建抬头文本
  5. (BADI)Copy PR header text to PO header w
  6. Submit report 很实用FM:RS_REFRESH_FROM_
  7. 修改盘点数量MI04过账
  8. Dialog屏幕调用选择屏幕
  9. 创建采购申请(BAPI_REQUISITION_CREATE /
  10. (EXIT)Copy PR header text to PO header w