Welcome to the 2nd edition of the Android Tidbits series! Like we said in our first tidbits post last week, this is a semi-regular blog post series where the Android team shares development tips and tricks (“tidbits”) with you. We encourage everyone on our team to tidbit as much as they can throughout the week, even if a tidbit might seem obvious to them. After all, you never know when that one piece of information you share might teach someone something new. We hope you find this week’s tidbits helpful.

Tidbit 1

If Android decides to update the system’s Webview while your app is running, it might crash your app: http://stackoverflow.com/questions/29575313/namenotfoundexception-webview

Tidbit 2

Material Design has standard padding and margins that some of your views should respect. Unless you’ve trained in the art of seeing padding mistakes and have already realized that every word in this tidbit has two spaces between it, then try out this app to make sure everything is lined up right in your app: https://play.google.com/store/apps/details?id=com.faizmalkani.keylines

Tidbit 3

getChildLayoutPosition will return a position even if you removed an item from the list in the adapter because the view might be animating out and still in the RecyclerView.

Tidbit 4

GET\_ACCOUNTS is the one runtime permission that cannot be disabled on targeting pre-API 23 apps via the permissions page (in fact, if that’s the only permission in the Contacts group, you won’t even see the Contacts group as an option). Breaks too many apps that assumed an account exists.

Tidbit 5

Chrome changed the way it handles deep links. You can no longer accidentally trigger a deep link by simply typing a URL into the address bar. For example, you used to be able to type “pandora.com” into Chrome’s address bar, and the Pandora app would open instead of the user being taken to Pandora’s webpage. With the new behavior, the user will actually be taken to Pandora’s website. Also, to deep link into an application from your website, you need to format your link using the following new format: intent:

intent:
   HOST/URI-path // Optional host 
   #Intent; 
      package=[string]; 
      action=[string]; 
      category=[string]; 
      component=[string]; 
      scheme=[string]; 
   end;

For example:

<a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;end"> Take a QR code </a>

Pro-Tip: You can include a fallback URL and/or a package name in the link as well. These will provide fallbacks for when the user does not have your app installed. First Chrome will check for a fallback URL and navigate the user there. If no fallback URL is provided Chrome will look for the package name, and the user will be taken to the Play Store for that package. If the user does not have your app installed and no fallbacks are provided, the user will see a 404 Not Found page. Read more about it here: https://developer.chrome.com/multidevice/android/intents

Tidbit 6

Watch out using Loaders on support 23.0.0. Due to a change in the way Fragment’s work with Activities, a bug was introduced that leads to loaders being lost on orientation change. This is fixed in 23.1.0, however, there is still an issue where loaders in child fragments are lost on orientation changes. The fix at the moment is to use support versions < 23.0.0.

Tidbit 7

On OSX you can summon the Dock on a different display by dragging the cursor to the bottom of that display and continuing downward. Not strictly android related but if you have multiple monitors on a mac then this has probably driven you crazy every once in awhile. If you have your dock somewhere other than the bottom then check the comments for other routes!

Tidbit 8

Use Collections.emptyList() and Collections.emptySet() when possible instead of returning a new empty collection from a method. The collections class takes care of a single instance of an immutable empty list/set, no need to new up another one.