个人资料封面照片
个人资料照片
伍业雄
47 位关注者
47 位关注者
简介
信息

此信息包含已分享的内容
A flowchart for background work, alarms, and your Android app
Pro-tip by +Ian Lake

For many apps, doing work in the background can be an important part of building a great experience. An alarm registered with AlarmManager (http://goo.gl/FtpShV) is one way to schedule your app to be run sometime in the future, even if your app isn’t in the foreground. What alarm type and API should you use for your app or are alarms even the best option? Let’s go through some of the factors that should influence your opinion:

How often do you want to trigger?
For events less than 60 seconds apart, alarms aren’t the best choice: use the much more efficient Handler (http://goo.gl/CE9vAw) for frequent work.

Want to set a user visible alarm clock?
On API 21+ devices, new APIs allow you to set a user visible alarm via setAlarmClock(): the system UI may display the time/an icon and apps can retrieve the next alarm clock with getNextAlarmClock(). Note that alarms set with setAlarmClock() work even when the device/app is idle (similar to setExactAndAllowWhileIdle()): getting you as close to an exact wake up call as possible. For backward compatibility, you’ll follow the same guide below for a single alarm.

Wake up the device/app while idle (i.e., doze, app standby)?
On Android 6.0+ (API 23) devices, additional power-savings optimizations (http://goo.gl/dVtgz6) have been added in the form of Doze (triggered by a completely stationary, unplugged, and idle device) and App Standby (triggered by an unplugged device on idle apps that haven’t been used recently). You’ll use setAndAllowWhileIdle() for inexact and setExactAndAllowWhileIdle() for exact alarms if you need it to fire an alarm while in these idle states. If it can wait until the user returns to their device/your app, use the standard set() and setExact() to be the best Android citizen and save your user’s battery.

(We’ll be talking more specifically about Doze and App Standby later!)

Just a single alarm?
A single alarm can be set with the aptly named set() method. One thing to keep in mind is that on API 19+ devices when you target API 19+, the system will be treated as inexact, potentially batching alarms together - the alarm will never go off before the time specified, but may go off afterwards. If you have some flexibility in the start time but have a hard deadline, consider using setWindow() to gain more control over the exact time period to be used.

You can use setExact() for a precisely timed single alarms on API 19+ devices, but use these only when the exact timing is required (such as with a calendar reminder).

Need to repeat at a constant rate?
For repeating alarms, batching is the key to good battery life. setInexactRepeating() does exactly that. Prior to API 19, you can use one of the INTERVAL_ constants (such as INTERVAL_HOUR to batch alarms of the same interval. On API 19+ devices, all repeating alarms (no matter what the interval) set with setInexactRepeating() will be batched.

You’ll note there’s also setRepeating() - similar to set() the behavior changes with API 19 from exact to inexact repeating alarms, meaning if you are on an API 19+ device and target API 19+, this functions identically to setInexactRepeating(). If you really need exact repeating alarms on API 19+, set an exact alarm with setExact() and schedule the next alarm once your alarm has triggered - keep in mind the battery implications though!

BUT WAIT: should you even use alarms?
If you want to be as battery efficient as possible (and you should!), consider using JobScheduler (https://goo.gl/CQjbsp) on API 21+ devices or GcmNetworkManager (https://goo.gl/CGNi3p) on all Google Play services enabled devices of API 9+.

Supporting both one off and periodic work, these APIs lack the ability to wake from idle, but gain the ability to wait for network access, wait until the battery is charging, take advantage of automatic backoff and retry, persist across reboots, and batch jobs across the system (meaning lower battery usage!).

That’s a lot of good reasons to use JobScheduler and GcmNetworkManager so consider them strongly in your push to #BuildBetterApps
照片
发表评论…

此信息包含已分享的内容
Searching…
The material design spec says¹ that “transitioning between two visual states should be clear, smooth and effortless and not confuse the user”.  That's why when I came across this shot² on dribbble I thought it was a pretty funky way to transition from a search icon to a search field.  I then thought that with AnimatedVectorDrawable's³ ability to animate paths, this would be simple.  +Chris Banes said I was crazy so then I had to make it to prove him wrong.

https://gist.github.com/nickbutcher/b3962f0d14913e9746f2

#AndroidDev   #materialdesign  

¹ http://www.google.com/design/spec/animation/meaningful-transitions.html#meaningful-transitions-visual-continuity
² https://dribbble.com/shots/1945376-Search
³ https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html
动画照片
发表评论…

此信息包含已分享的内容
Use colorPrimary to colorize your App Bar
Pro-tip by +Ian Lake 

The app bar [1], or action bar, is an iconic part of many Android apps, providing a consistent place for navigation affordances and frequent, important actions. But it can also be a great opportunity to bring some personality to your app. An easy way to do that is by using your branding color as the background of the app bar.

In fact, AppCompat makes this very straightforward using a technique of providing a color palette [2] for your app. While introduced in the Material themes added in Android 5.0, AppCompat makes this technique available to all Android 2.1+ devices.

If you’re using a theme such as Theme.AppCompat, you’d only need to add a colorPrimary attribute:
<style name="AppTheme" parent="@style/Theme.AppCompat">
<item name="colorPrimary">@color/primary</item>
</style>

And your App Bar will automatically be colored appropriately. You’ll note we’re using just colorPrimary and not android:colorPrimary as android:colorPrimary only works on Android 5.0 devices unlike the AppCompat provided colorPrimary. Just make sure you’re using the right theme so that the text and icons have enough contrast:
- Theme.AppCompat -> dark activity, dark app bar
- Theme.AppCompat.Light -> light activity, light app bar
- Theme.AppCompat.Light.DarkActionBar -> light activity, dark action bar

But perhaps you’ve already moved over to Toolbars (perhaps wrapped in the Design Library’s AppBarLayout [3])? In those cases, you’re probably using a Theme.AppCompat.NoActionBar or Theme.AppCompat.Light.NoActionBar theme and including those elements in your layout XML files. Thankfully, you can still take advantage of your colorPrimary using the format ?attr/colorPrimary:
<android.support.v7.widget.Toolbar
android:background="?attr/colorPrimary" />

This ?attr/ format allows you to pull any attribute out of your theme, making it easy to consolidate your theming into a single place and avoid finding/replacing across many files.

The other thing we’ve lost is our text coloring though - there’s no Theme.AppCompat.Light.DarkActionBar.NoActionBar. Here’s where a ThemeOverlay can prove incredibly helpful. ThemeOverlays, unlike a full theme, only seek to overlay the current theme, changing the few things they need to. For example, if we had a light theme but wanted a dark Toolbar, we could use:
<android.support.v7.widget.Toolbar
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
With just that change, our text and icons are now back to a white color - perfect for a dark Toolbar.

You’ll find a number of other colors you can and should add to your theme such as colorPrimaryDark for changing the status bar on 5.0+ devices to a darker branding color and colorAccent for a contrasting accent color designed to make elements such as a FloatingActionButton really pop out. If you’d want to learn more about AppCompat, check out our video on Consistent Design with AppCompat [4].

For now, bring some personality to your app by using colorPrimary to color your App Bar or Toolbar!

#BuildBetterApps

[1] - http://goo.gl/Meu1sE
[2] - https://goo.gl/EHaUMj
[3] - https://goo.gl/Wo1IBv
[4] - https://www.youtube.com/watch?v=5Be2mJzP-Uw
发表评论…

此信息包含已分享的内容
发表评论…

此信息包含已分享的内容
The video from my talk "A Few 'Ok' Libraries" from +droidcon Montreal is now available for viewing. This covers the behavior of Okio and how the OkHttp, Moshi, and Retrofit libraries interact with it to move and parse data efficiently.

#AndroidDev
发表评论…

此信息包含已分享的内容
An android sample project implementing a parallax effect welcome page, similar to the one found in google's app like Sheet, Docs, Drive...
https://github.com/matrixxun/ProductTour
动画照片
发表评论…

此信息包含已分享的内容
转给凯哥的
Introducing new Android training programs with Udacity

We know how important it is for you to efficiently develop the skills to build better Android apps and be successful in your jobs. To meet your training needs, we’ve partnered with +Udacity to create Android training courses, ranging from beginner to more advanced content, as well as the newly announced Android Nanodegree, an education credential designed for busy people to learn new skills and advance their careers in a short amount of time from anywhere at any time. 

To learn more about our Android training programs with Udacity, check out the blog post below, or RSVP for our live "Ask the Experts" session with +Sebastian Thrun,+Peter Lubbers and Jocelyn Becker on Wednesday, June 3rd at 2pm PDT. (https://goo.gl/W5dPVv)

#AndroidDev   #Udacity  
发表评论…

此信息包含已分享的内容
Excellent!
100 days of Google Dev, Episode 2/100:

Swapping Bitmaps in-and-out of memory is hard. Use LRUCache instead

Caching is one of the most difficult topics in computer science (alongside finding a cool name for your company, or your project) but you don’t have to worry too much about it, as Android’s LRUCache will do all the heavy lifting for you. +Colt McAnlis presents this awesome container, and gives you some tips to get the most out of it.

Watch more Android Performance Patterns here: http://goo.gl/4ZJkY1

Join the G+ Community here : http://goo.gl/g7mxmI   #PERFMATTERS

Subscribe to our channel now for updates as we release new videos: http://goo.gl/mQyv5L

#GoogleDev100
发表评论…

此信息包含已分享的内容
The new support annotations are now included in http://tools.android.com/tech-docs/support-annotations

And (drumroll please) : as of 1.3, all these annotations are now not only checked within the IDE, but are checked from lint on the command line/on your build server as well! (Except for the nullness annotations.)
发表评论…

此信息包含已分享的内容
正在加载更多信息,请耐心等待