<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Brendan Fahy on Medium]]></title>
        <description><![CDATA[Stories by Brendan Fahy on Medium]]></description>
        <link>https://medium.com/@brendan_fahy?source=rss-4bf330e78d72------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*gAycry7OXRTl2KsLGmoUcw.jpeg</url>
            <title>Stories by Brendan Fahy on Medium</title>
            <link>https://medium.com/@brendan_fahy?source=rss-4bf330e78d72------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 23:23:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@brendan_fahy/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Value of Google I/O, for You and Your Company]]></title>
            <link>https://proandroiddev.com/the-value-of-google-i-o-for-you-and-your-company-780d0c832785?source=rss-4bf330e78d72------2</link>
            <guid isPermaLink="false">https://medium.com/p/780d0c832785</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[google-io-2017]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Brendan Fahy]]></dc:creator>
            <pubDate>Wed, 07 Jun 2017 18:23:51 GMT</pubDate>
            <atom:updated>2017-06-07T18:23:51.706Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-dfA_axpCN_G__tK4xd5Xg.jpeg" /></figure><p>I went to Google I/O for the first time this year, and it was amazing. They gave us a free Google Home, and there were all these insane fun tech demos and games and toys, all showing off cool stuff like machine learning and the Google Assistant, and there was a party and free beer, and they got LCD Soundsystem to play a concert for us, and and and and and…</p><h3>Google on Twitter</h3><p>Schedule accordingly. #io17</p><p>All of that stuff was great. And when someone asks you what Google I/O was like, you start showing them photos of the cool stuff you saw, or you talk about the announcements in the keynote, or the talks you attended. But none of that is the real reason to go to I/O.</p><p>A friend told me a story recently. The Android developers of his company, when they returned from I/O, gave a presentation about their experience there for the rest of the company. At the end, somebody asked a question, “Sure, it looks like you had a lot of fun, but what did we gain from this?”</p><p>And no one had a good answer.</p><h3>Why should we pay for you to go to Google I/O?</h3><p>Google I/O tickets are hard to get, and they’re expensive. For those attendees who don’t live in the area, it’s even more expensive, because you need to pay for accommodation. And for those attendees who are flying from Ireland (like me!), or Asia, or wherever, there’s the cost of that too. Even if you get a free ticket through one of the <a href="https://developers.google.com/experts/">GDE</a>, <a href="https://developers.google.com/groups/">GDG Organiser</a>, or <a href="https://developers.google.com/agency/">partner organisation</a> routes, the other costs are still there. But it’s OK, because our employers pay for it, right? Through expenses, or conference budgets, or calling it training or professional development, or whatever other gymnastics of accounting they contort it into, they pay for you to go. It seems reasonable to assume that most software developers can’t afford to spend a few thousand dollars on a three day conference, so we rely on our employers to get us there.</p><p>Businesses care about money. To greater and lesser degrees, they care about what’s costing them money. To greater and lesser degrees, they care about investing in their employees. Invariably, some employers will question the value of sending you to a conference like Google I/O, when it costs several thousand dollars to do. This question might not be intended harshly. It might be genuine curiosity from someone who is excited by your excitement, and wants to know how it will affect your work and their company going forward. But if you can’t answer that question, and communicate real value gained from your attendance, your employer may reconsider paying for it next year.</p><h3>“You can watch it all on Youtube!”</h3><p>Videos of talks from I/O have been going up on Youtube since <a href="https://www.youtube.com/watch?v=vk1HvP7NO5w">the first I/O in 2008</a>. (Side note: I know this because I just asked my Google Home when the first I/O was, and it told me. Then I asked if there were any videos on Youtube from I/O 2008. It apologised, and said it couldn’t help me with that yet. So I opened a new tab in Chrome and looked it up myself. Like some sort of cave-dwelling <em>savage</em>.)</p><p>The keynote is streamed live. Nowadays, many (all?) of the talks are streamed live. The videos are all up on Youtube afterwards. So, logically, you can get all of that learning without attending the event, right? I disagree. You can get <em>most</em> of <em>that</em> learning without attending. There are still things that happen that can’t be replicated after the fact. You lose the chance to ask questions, for one. You miss the opportunity to speak with the developers sitting next to you (more on that later).</p><p>That’s not a strong enough argument though. No profound experiences are <em>guaranteed</em> from attending a talk in person, and you can get <em>most</em> of the value of a talk by watching the video. But that’s not all there is to attending a conference.</p><h3>The real value of attending Google I/O is <em>not</em> the talks</h3><p>The real value is the free Google Home they gave us this year.</p><p>Just kidding. It’s not the Google Home. It’s not the mocktail a robot made for you because you asked nicely, or the slow-mo Matrix-style rotating video of you and your friends putting on sunglasses at night, or the LCD Soundsystem concert (though that was incredible), or the talks you went to (which you can watch at home).</p><p>The real value of going to I/O is all those moments that happen off-camera, between the pictures. I/O gives you direct access to Google engineers and experts in a way you can’t get anywhere else. What with the sandboxes, app review sessions and office hours, there is no better opportunity to talk about the problems you face in your development with someone who can help. In some cases, they’re the people that work directly on the tool/library/framework you’re struggling with. Wondering how you could architect your system on Firebase? There’s a Firebase sandbox, where you can work it out with the experts on a big whiteboard. Having a problem with something in Android Studio? Head to the Android sandbox, find the Android Studio desk, talk to Tor Norbye or one of his team about it. Still have questions about Room or LiveData after the Architecture Components talks? Go find Yigit and the guys at the Support Library stall. They’re waiting there to talk to people just like you, looking for feedback, ready to answer your questions. They even have this weird picture of Chris Banes in front of an explosion, for all your selfie needs.</p><h4>Making it Real</h4><p>Have you, or your company, ever partnered with another company in some way? Have you worked on a project where you dealt with people online, but had never spoken to them or met them face to face? It’s so easy to forget that the people on the other side of the screen are <em>people </em>(as seen on <a href="https://en.wikipedia.org/wiki/Online_disinhibition_effect">The Internet</a>)<em>, </em>but when you meet them in person, that changes completely. When you can put a face (not just an avatar image on Github or Slack) and a voice to a name, your working relationship with them undergoes a drastic improvement. Conferences are a great place for these meetings to happen, and I/O is a big conference. There’s a reasonable chance your partners are going to be there.</p><p>At Zendesk, my team works on our <a href="https://developer.zendesk.com/embeddables">mobile SDKs</a>. We recently <a href="https://support.zendesk.com/hc/en-us/articles/115002794707-Announcing-the-Zendesk-kit-for-Fabric-easier-in-app-support-with-plug-and-play-analytics-using-Answers">partnered</a> with <a href="https://www.fabric.io/kits/android/zendesk">Fabric</a> to add the Zendesk Support SDK as a Fabric Kit. Naturally this work involved communication with people in Fabric, and naturally most of this communication was done online. We got to meet them at I/O, and finally feel like we really know who they are. I’m already looking forward to our next collaboration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xSTz5HJND0-4vDkPlpVFbg.jpeg" /></figure><h4>Developers</h4><p>At I/O, you’re constantly surrounded by people whose brains are soaked in the same stuff as yours. Every one of the hundreds of people in every talk you go to most likely works in your field, and you never know who you’ll be sitting beside. The people in front of you in the queue, or sitting beside you when you’re eating lunch, or at the bar or absolutely anywhere — they’re always worth saying hi to. It might be an awkward ten-second exchange of pleasantries with a stranger, or you might realise you’ve read everything they ever wrote on their blog. You might overhear someone sharing thoughts and impressions about a talk, giving some insight you hadn’t picked up on, hearing what they do, what they struggle with, what they’re looking forward to. It’s ear to the ground, finger on the pulse. It’s that magic tree in Avatar. It’s the hum of the worker bees, except the hive is the global developer community of your field. It’s the developer zeitgeist. You simply can’t get that anywhere else.</p><p>Google Developer Experts get free tickets to I/O, so you see a lot of them there. One of the things that makes them GDEs is their contribution to the developer community. So think about all your favourite blogs and podcasts and libraries; their authors are probably at I/O. Some of them are probably even giving talks there. Others might be regular speakers in your local developer community. You have the chance to speak to them and ask them questions. They’re friendly people!</p><h4>Community</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TzGiNIs6nxvfWYNQ-ddNgg.jpeg" /><figcaption>A simple message on the big screens at night</figcaption></figure><p>I was lucky enough to attend the Global Developer Community Organiser Summit, the day before I/O started. While this isn’t relevant to everyone, as one of the organisers of an Android developer meet-up, it was an incredible experience to mingle and talk with organisers of Google Developer Groups and other communities all over the world. And just like the main I/O conference, the true benefit for me was not in the scheduled talks, but in these organic conversations that happened in the moments in between. The table full of strangers I joined for lunch was the best part. I spoke with people running events in Romania, Kuwait, New York, Malaysia, Poland, India… the list goes on. We talked about what kind of events they run, what format, how often, how many attendees they get, what problems they face, how our communities differ in form, size, or behaviour.</p><h3>Getting Closer</h3><p>The thing that surprised me the most about going to I/O was how much the distance between myself and Google seemed to disappear. Admittedly, I was suddenly 1km away from the Googleplex instead of the usual 8,000, so I was literally much closer, but I don’t think that’s it. It’s not just Google that felt closer, it’s also the big players of our wider developer community.</p><p>It’s easy to feel that we exist in some sort of feudal hierarchy where Google reigns on high from an ivory tower, with the writers of your favourite blogs and the podcast people below them, and some indeterminate number of other ranks between you and them. Maybe this is partly a symptom of living so far away from the epicentre that is California. Maybe it’s just imposter syndrome. Maybe the realities of the world promote or enforce aspects of it. I’m not sure, but regardless, the feeling is there.</p><h3>Lisa Wray on Twitter</h3><p>Slowly realizing I could literally cure cancer and the headline would read, &quot;Ex-Googler Finds Cancer Cure</p><p>At I/O, those barriers seem to fall away. I got to ask Chet Haase and Tor Norbye (two high-profile Android leads at Google and hosts of the Android Developers Backstage podcast), what they thought developer communities <em>could </em>be doing for them, what they saw as the goal or value of such communities, and their answer was basically: “give us feedback”. They want us to tell them what they’re doing right and wrong, and how <em>they</em> can help <em>us</em>. This was a repeated theme in my conversations with Googlers. When I talked to someone in the sandbox about a problem I have in Android Studio, he asked me to file a bug report for it. And not in a “go away” kind of way, but in a genuinely interested way. They can’t fix it if we don’t tell them about it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YpJgEgyIey9-Vab69dZW-A.jpeg" /><figcaption>Tor and Chet at the Global Developer Community Organiser Summit</figcaption></figure><p>I thought see if I could find someone to help me with some Google Play Services/GoogleApiClient stuff I’ve struggled with. This, I figured, was a long shot, since it was 3pm on the last day of the conference. Things were winding up, people were departing. I didn’t see any stalls in the Android sandbox that looked particularly likely to have answer for me, so I asked one of the Googlers if they could point me in the right direction. They tried, so I went and asked at the desk they’d directed me, who sent me on to someone else, and from there to another one. In the end, I never got my answer. But what I did get was four or five of the Android engineers in the sandbox — the people I’d been watching speak on stage all week — who dropped what they were doing to try to help me. They didn’t know the subject matter so they were trying to find someone who did. They were grabbing other Googlers to ask them if they knew, pinging Hangouts groups to check if anyone there could help… It was great. It didn’t feel like an ivory tower then. It just felt like developers trying to help other developers. That’s a huge sea change from the way it normally feels.</p><h3>Developers, developers, developers, developers</h3><p>I think developers have an almost instinctual need to help other developers. Individuals, in general, want to help other individuals. Just look at <a href="https://stackoverflow.com/">StackOverflow</a>. Google I/O is full of developers like that — like you. All of them trying to become better and more effective at what they do. I’ve always liked the phrase, “A rising tide lifts all boats.” As our environment improves, so do we. I/O is a chance to be part of that tide, as well as being a boat.</p><p>Apart from all that, I/O offers a chance to make and strengthen industry connections. It gives you visibility on the most current industry trends. You get direct access to the authorities in your field and the producers of the technologies you use. It raises your company’s brand and brand-awareness. It is an opportunity to get and provide feedback, on your projects and on Google’s.</p><p>And yes, it is a hell of a lot of fun. So don’t let your employer think that’s all it is. The true value of I/O is intangible. It can’t be captured in pictures, and if it could, they’d be really boring pictures.</p><h3>Signing Off</h3><p>This all comes from my own personal experience of one year’s I/O conference, which isn’t a whole lot to go by, but I hope it is of value to somebody. I’d be very interested to hear what other people think, the parts they agree or disagree with, or anything I may have left out. Do let me know.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=780d0c832785" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/the-value-of-google-i-o-for-you-and-your-company-780d0c832785">The Value of Google I/O, for You and Your Company</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interviewing Android Developers]]></title>
            <link>https://medium.com/android-news/interviewing-android-developers-435ce69b06fa?source=rss-4bf330e78d72------2</link>
            <guid isPermaLink="false">https://medium.com/p/435ce69b06fa</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[android-developers]]></category>
            <dc:creator><![CDATA[Brendan Fahy]]></dc:creator>
            <pubDate>Wed, 12 Apr 2017 09:16:26 GMT</pubDate>
            <atom:updated>2017-04-26T17:17:09.824Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r-YkVF5BhcZsqTRrY0TGEA.jpeg" /></figure><p>A friend of mine recently asked me for some advice about interviewing Android developers. We talked for a while, and I said I’d write some stuff down and send it to him. Over the last few years I’ve interviewed dozens of candidates from around the world, and brought several colleagues in on in the interview process to share the experience with them too. As a byproduct of that, there were emails and wiki pages full of attempts to distil our thoughts into something informative and concise.</p><p>By no means am I an expert on the subject, but when I first started, I found immense value in some thoughts a senior colleague shared with me, on what to ask and what to look for. I hope that by writing these words, I can someday provide that value for someone else.</p><h3>Interviews are hard, for both sides of the table.</h3><p>Being an interview candidate is a nerve-wracking situation. It can also be intimidating, and in some rare cases, humiliating. It’s easy to suffer from a bit of <a href="https://en.wikipedia.org/wiki/White_coat_hypertension">white coat syndrome</a>, performing more poorly than you would if you weren’t in an interview. I forgot what Maps were for, once.</p><p>Being the interviewer is also difficult. You have a short amount of time to gain enough information about a human being to make a decision about them that has potentially huge implications to them, to you, and to the company.</p><h3>Interviews should be conversations</h3><p>I have a bee in my bonnet about the way some people do interviews.</p><p>I hate the notion that an interview is a unidirectional series of questions that have right and wrong answers. We might as well just hand people a paper questionnaire to fill out. Why bother interviewing them if we’re going to do it like this? It’s unnecessarily adversarial. It shines a searchlight on the candidate, limiting the scope of what can be learned to only those things which fall within the searchlight’s narrow beam. Anything you don’t ask, you don’t hear about. The candidate learns nothing about you or your company, except that you view this as an acceptable way to treat people. Is this what working there will feel like?</p><p>This is an extreme example, obviously — I’m sure even the most scripted set of interview questions allows room (admittedly, at the end) for any questions the candidate might have. But still, what’s the point? Surely that’s not what conversations in your team are actually like. If you’re trying to get a feeling for what it would be like to work with this person, shouldn’t the interview try to approximate that situation?</p><p>I like an interview to feel like a real conversation. Sure, one person is trying to convince the other to give them a job, but that doesn’t mean it can’t still be a chat. If you’re interviewing someone, there’s a good chance you’ll be working closely with them if they get the job. That can mean sitting beside them for eight or more hours a day, five days a week, forever. Or maybe you’ll just be dealing with each other’s code all the time. Or anything in between. You should be able to talk to them, freely and comfortably.</p><h3>How to have the conversation</h3><p>While I like to treat an interview as a conversation, it still needs to have direction. I still have things I want to find out, things I want to talk to them about. I like to break it up into several sections, and I’ll outline that basic structure to the candidate at the start of the interview. These sections are flexible, both in time and specific aspects of the subject matter. Sharing the structure with the candidate helps them feel more comfortable; it gives them an idea of what to expect, and extends a friendly gesture of information-sharing. It’s subtle, but it makes a difference.</p><p>Once we’re ready to go, I use questions to open up discussions, or as follow-up questions to clarify details. Closed questions, with right/wrong answers, are generally less useful.</p><h4><strong>Openers: Android basics</strong></h4><p>I like to start with some questions on Android basics, starting with a particularly easy question. This serves the double purpose of both putting people at their ease by giving them a quick and easy win, and flagging a surprising number of people who clearly don’t know a lot about Android.</p><ul><li>Can you describe the Activity lifecycle?</li><li>Can you describe the difference between a Service and a ContentProvider?</li><li>How would you persist data in an Android app?</li><li>How would you perform a long-running operation in an application?</li><li>How would you communicate between two Fragments?</li></ul><p>If these questions seem vague, they’re supposed to. The Activity lifecycle should be pretty straightforward and self-explanatory, but beyond that all of these questions should be most often answered with either “it depends” or a question from the candidate. This strengthens the conversational nature of the interview, since more communication is required from both sides to move forward. As any capable Android developer will know, there are multiple ways to persist data, to perform long-running operations, and to communicate between Fragments. All of these things — even using Fragments at all — are worthy topics of discussion. They can tell you a lot about how someone approaches things and what they’ve done.</p><h4><strong>Tools and technologies</strong></h4><p>It’s always a good idea to get an idea of what kind of tools and technologies someone uses to do the job. If they’re still using Eclipse, or vim, or anything that’s not Git, I want to know why. For the most part, people answer with Android Studio and Git. That’s great. But it’s still good to find the outliers.</p><p>Android development has a huge community of third-party open-source libraries, and a strong affinity for using these libraries to avoid reinventing the wheel. Of course, it’s possible for people to go overboard, solving (perceived) problems in their apps by applying third-party solutions, without fully understanding the problem, or the solution, or both. I find it helpful to ask about solutions candidates have used, focusing on categories rather than specific libraries. Here’s a few:</p><ul><li><strong>Networking</strong>: <a href="http://square.github.io/okhttp/">OkHttp</a> and <a href="http://square.github.io/retrofit/">Retrofit</a> have become pretty ubiquitous these days. <a href="https://developer.android.com/training/volley/index.html">Volley</a> still pops up from time to time though, and I’m always curious to find out why someone favours it. I still have nightmares about <a href="http://projects.spring.io/spring-android/">Spring RestTemplate</a>.</li><li><strong>JSON serialisation/deserialisation</strong>: most people use <a href="https://github.com/google/gson">GSON</a> these days, though <a href="https://github.com/square/moshi">Moshi</a> is growing in popularity. I find Moshi to be a great topic for a bit of discussion, as its advantages over GSON are not immediately obvious to someone unless they’ve looked into it. I can’t decide which one is more of a red flag to me — using <a href="https://github.com/FasterXML/jackson">Jackson</a> or doing it manually. Jackson’s method count is absolutely insane, and writing your own JSON handler is time-consuming, brittle, and downright unnecessary.</li><li><strong>Source control</strong>: as mentioned above, I find it very strange in this day and age if someone isn’t using (or has never used) Git. Leading on from that, I’m curious about <em>how</em> people use Git, both from a process point of view and a tools point of view. Do they use feature branches? Do they use pull requests? Do they have a develop and a master branch, or just master? Personally, I find myself commonly using both terminal and Android Studio’s Git client for my general needs (creating/switching branches, creating commits, rebasing, merging etc), and occasionally going to <a href="https://www.sourcetreeapp.com/">SourceTree</a> for visualisation. But when something gets mixed up and I end up in a confusing conflict state that needs to resolved, I put all GUIs aside and go back to the ultimate source of truth, the terminal. Some people have never worked with Git on the command line. I find that worth talking about.</li><li><strong>Dependency injection</strong>: with the rise of Dagger (1 and 2), dependency injection has become much more common in Android apps. And as anyone who uses it can tell you, it’s fantastic. But it’s important to know what dependency injection is, how it’s implemented, and why we want to do it in the first place. What makes <a href="https://google.github.io/dagger/">Dagger 2</a> better than <a href="http://square.github.io/dagger/">Dagger 1</a>? Are there any other dependency injection solutions for Android? What’s good/bad about them?</li><li><strong>RxJava</strong>: I’m a huge fan of <a href="https://www.google.ie/webhp?sourceid=chrome-instant&amp;rlz=1C5CHFA_enIE706IE710&amp;ion=1&amp;espv=2&amp;ie=UTF-8#q=rxjava&amp;*">RxJava</a>. It changed the way I write Android apps. I love it. Not everyone uses it, not everyone has used it, and that’s fine. But it has been a hot topic in the Android community for some time now, and if someone hasn’t heard about it, or hasn’t tried it, that’s not a great indication of their awareness of the state of the art, or their interest in trying new things. If they have used it, I want to know how much. What’s your favourite thing you’ve ever done with RxJava? What were the hurdles or drawbacks you found?</li><li><strong>Kotlin</strong>: <a href="https://kotlinlang.org/">Kotlin</a> is a lovely language. It’s another hot topic in the Android development community. Like RxJava, I’m curious about whether people have used it, and what they thought of working with it. What’s your favourite feature of the language? Did you ever have any problems with it?</li><li><strong>Android Support Libraries</strong>: part of Google’s partial solution to the age-old fragmentation problem that <a href="https://www.google.ie/webhp?sourceid=chrome-instant&amp;rlz=1C5CHFA_enIE706IE710&amp;ion=1&amp;espv=2&amp;ie=UTF-8#q=android&#39;s+fragmentation+problem&amp;*">tech journalists like to crow about</a>, the support and design support libraries have become fairly ubiquitous. The advent of Material Design only strengthened this. But they bring with them their own problems. These are worth talking about. It’s also good to ask about some of the less common, or newer components. At the time of writing, ConstraintLayout is one I’d ask about. VectorDrawable too.</li><li><strong>Google Play Services</strong>: I’ve recently come to blows with GoogleApiClient and some of the Google Play Services APIs. They can be somewhat awkward to use, but provide immense power to your app when used correctly. I like to hear what a candidate experiences are with Google Play Services.</li></ul><h4><strong>Testing</strong></h4><p>I consider testing to be its own section in my list of topics to cover. It’s important. In the early days, the state of testing on Android was quite poor, but it’s come along by leaps and bounds over the last couple of years, with JVM JUnit tests, Espresso, and the Android Testing Support Library. Talking about testing naturally involves talking about app architecture — an app isn’t testable unless it was written to be testable. So this has some crossover with the dependency injection questions mentioned above, but also has potential to bring in MVP in its various incarnations, MVVM, and any other strategy someone might use to structure their app’s code.</p><p>For a candidate above the level of intern or junior developer, I want to hear that they’ve had some exposure to:</p><ol><li>Unit testing</li><li>Instrumentation testing</li><li>UI testing with Espresso</li></ol><p>And I want to hear what their opinions are about all of these things.</p><h4><strong>CV projects and war stories</strong></h4><p>When you read over the CV of a candidate, make a note of anything on it that caught your eye. In the interview, ask about each one of those things.</p><p>Writing a CV is a horrible exercise in trying to fit a lot of information into a relatively short document and still having it nicely formatted with plenty of friendly bits of whitespace. You have to prioritise and cut and revise, and sometimes your best or most interesting work only gets a couple of words on the page. It’s important to provide an opportunity for people to talk about these things.</p><p>Some stuff doesn’t get a place on the CV, but can still be very relevant. What was your favourite, or “best” project that you worked on? Why?</p><p>As well as the good stuff, it’s useful to ask about the bad. I like to ask about the most difficult problem (or project) a candidate has encountered, and what they did to solve it (<em>did</em> they solve it?). How did they approach that difficulty? It doesn’t necessarily have to be technical. It could be something about the team or the customer. Either way, it can tell you a lot about someone — good or bad.</p><h4>Personal interest in Android/technology</h4><p>This is the last section in my list. I feel like this can be the most casual, most informal part of the whole conversation. The goal is to get a sense of how much the candidate is really interested in Android, or in technology in general. For some people, it’s just a job, and that’s OK. For others, they go home every night and work on their own side projects or read every tech article they can. It’s good to know these things, to get a better understanding of who you’re talking to.</p><p>I try to frame a question around the candidate and their experience of (or interest in) some aspect of the wider tech/Android world, preferably something recent. Is that a Moto 360 on your wrist? Were you at Droidcon [location] last week? Did you watch the I/O keynote yesterday? All of these questions serve to open a topic for more conversation. Personally, I want to hear that a candidate had some engagement in something like the I/O keynote — they should have at least one opinion about at least one announcement, and something they’re curious to hear more about.</p><p>How do you keep up to date with Android news? I always ask this at the end, and I’m not sure if it’s for me or for them. Any particular blogs, websites, podcasts — I can barely keep up with all the ones I follow, but I’m always curious to hear what other people are using.</p><h3>Closing up</h3><p>It’s important to leave time for candidates to ask any questions they might have. Obviously these don’t have to wait until the end, but it’s good to explicitly prompt them for any questions they didn’t get a chance to ask already. You’re interviewing them, but they’re also learning about you, and your company. Remember, it’s a two-way conversation.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e491f%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F3e491f%2F&amp;image=https%3A%2F%2Fe.enpose.co%2F%3Fkey%3DdRXnS9Gplk%26w%3D700%26h%3D425%26url%3Dhttps%253A%252F%252Fupscri.be%252F3e491f%252F%253Fenpose&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea6b55991f68b24354ca68fb5e19e10f/href">https://medium.com/media/ea6b55991f68b24354ca68fb5e19e10f/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=435ce69b06fa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/interviewing-android-developers-435ce69b06fa">Interviewing Android Developers</a> was originally published in <a href="https://medium.com/android-news">AndroidPub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Watts App Part 2 — Fixing the update frequency]]></title>
            <link>https://medium.com/@brendan_fahy/watts-app-part-2-fixing-the-update-frequency-f9a61d211797?source=rss-4bf330e78d72------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9a61d211797</guid>
            <category><![CDATA[android-wear]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Brendan Fahy]]></dc:creator>
            <pubDate>Sat, 28 Jan 2017 19:10:01 GMT</pubDate>
            <atom:updated>2017-01-29T01:38:17.454Z</atom:updated>
            <content:encoded><![CDATA[<p>In <a href="https://medium.com/@brendan_fahy/watts-app-is-my-phone-charged-yet-let-me-check-my-watch-1fea7e293995#">Part 1</a> I wrote about my inspiration and my first version of a simple little app that would show me the battery level of my phone on my Android Wear watch, while the phone was charging. Some problems became apparent once I’d finished. The main one was that the JobScheduler on Nougat enforces a minimum of fifteen-minutes between running jobs. In a world where <a href="http://gizmodo.com/new-quick-charge-tech-promises-5-hours-of-phone-battery-1789061446">quick-charging can give you five hours worth of battery life in five minutes</a>, restricting battery charge updates to fifteen minutes makes the app all but useless.</p><h3>Let’s try the AlarmManager</h3><p>JobScheduler proved itself to be overkill for my simple use case. Its optimisations to the running of repeated background tasks made it unsuitable for short-term frequent updates. Maybe this was because the job I wanted to schedule is much more basic than the type of operations it’s intended for (network calls etc).</p><p>I decided to try out <a href="https://developer.android.com/reference/android/app/AlarmManager.html">AlarmManager</a> instead. This has much less aggressive batching of scheduled tasks, and uses a BroadcastReceiver rather than a Service. The documentation contains this interesting note:</p><blockquote><strong>The Alarm Manager is intended for cases where you want to have your application code run at a specific time, even if your application is not currently running. For normal timing operations (ticks, timeouts, etc) it is easier and much more efficient to use</strong><a href="https://developer.android.com/reference/android/os/Handler.html">Handler</a><strong>.</strong></blockquote><p>The first sentence sounds about right — I want my application code to run at a specific time, even if it’s not running. The second part makes me wonder if Handler would work better for me, or if the documentation is referring to things like updating something on-screen during the lifetime of an Activity. I’ll have to try that approach sometime. For the moment, I decided to go with AlarmManager. It’s an API I’ve not used before, and I was curious about it.</p><h3>AlarmManager — Implementation</h3><p>The first step was to replace my old JobService with a BroadcastReceiver. The receiver has to be registered in the AndroidManifest, but doesn’t require any intent filters, so the declaration is simple:</p><pre>&lt;receiver android:name=&quot;.AlarmReceiver&quot;/&gt;</pre><p>The reason it doesn’t need any intent filters is because we’ll creating a PendingIntent which calls the receiver directly, like so:</p><pre>val alarmIntent = Intent(context, AlarmReceiver::class.<em>java</em>)<br>val pendingIntent = PendingIntent.getBroadcast(context, <em>JOB_ID</em>, alarmIntent, 0)</pre><p>The AlarmReceiver class itself looks almost exactly like the old PowerService class. It gets the NotificationManager system service, gets the latest battery information, and then fires a notification:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26f29153b3dc30553294fa145cf147f6/href">https://medium.com/media/26f29153b3dc30553294fa145cf147f6/href</a></iframe><p>In my PowerConnectionReceiver, I replaced the scheduling of a JobInfo in JobScheduler with the scheduling of my AlarmReceiver PendingIntent on the AlarmManager system service. I’ve supplied a value of zero for the triggerAtMillis parameter and a value of one minute (my JOB_INTERVAL constant) for intervalMillis, telling the AlarmManager to fire the first broadcast as soon as the charging event is detected, and repeat at one-minute intervals. Now it looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dcfd2d54aa0c503e734bf177989f73f6/href">https://medium.com/media/dcfd2d54aa0c503e734bf177989f73f6/href</a></iframe><p><strong>Side note:</strong> The batteryStatus variable in this snippet is the Intent which holds the latest battery info, but I’ve added a couple of <a href="https://kotlinlang.org/docs/reference/extensions.html">extension functions</a> to it so I can perform operations directly on the object, rather than passing it to another method as a parameter. In case you haven’t seen this before, it’s a lovely (and very powerful) feature of the Kotlin programming language. Try it out!</p><h3>AlarmManager kind of threatens to be a harsh mistress, but isn’t really</h3><p>As per the documentation:</p><blockquote><strong>Note:</strong> Beginning with API 19 (<a href="https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#KITKAT">KITKAT</a>) alarm delivery is inexact: the OS will shift alarms in order to minimize wakeups and battery use… Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested.</blockquote><p>This sounds familiar! There’s definitely some overlap with JobScheduler&#39;s batching optimisations, and these go back as far as Kitkat! But AlarmManager seems to be a lot more relaxed than JobScheduler. It might be “inexact”, but it’s not “a minimum of fifteen minutes”. I haven’t run any actual timing tests, but it’s at least been in the right ballpark. The shifting is likely to be more visible if working with shorter intervals.</p><h3>Great success!</h3><p>Once I’d swapped out the JobScheduler for AlarmManager (and remembered to register my AlarmReceiver in the Manifest, which was another brain-far moment), it worked like a charm! Again, most of the caveats and drawbacks of an AlarmManager strategy are not applicable to my use case, since my app only runs when the device is charging anyway.</p><p>But there’s still more room for improvement. The notification shows on both devices, so maybe I’ll create a Wear module so I can show the notification only on the watch. I realised I’d also like this functionality in reverse — a way to tell if my watch is charged yet, from my phone.</p><p><a href="https://github.com/brendan-fahy/wattsapp/releases/tag/alarm-manager">The code for WattsApp is available on my github.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9a61d211797" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Watts App” — Is my phone charged yet? Let me check my watch]]></title>
            <link>https://medium.com/@brendan_fahy/watts-app-is-my-phone-charged-yet-let-me-check-my-watch-1fea7e293995?source=rss-4bf330e78d72------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fea7e293995</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-wear]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Brendan Fahy]]></dc:creator>
            <pubDate>Thu, 19 Jan 2017 23:00:25 GMT</pubDate>
            <atom:updated>2017-01-28T19:09:25.832Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve had an Android Wear watch for the last 18 months or so, a first generation Moto 360, and I’ve always had a vague intention to <em>do something</em> with it. Something <em>cool</em>, some project I could pump a load of code into that would make this smartwatch truly <em>mine</em>. I’d looked at documentation about Android Wear. I’d read blog posts. I’d seen watch apps written live on stage at conferences, and deployed, in front of an ooohing, aaahing audience. I was going to do that too, and it was going to be awesome.</p><p>Except I could never figure out what to do. There’s no documentation for the APIs in our heads that return project ideas. Well, no Javadocs anyway. Definitely nothing Swagger-compliant.</p><p>Last week I found myself looking at my watch to see if my phone was fully charged yet. I was ensconced for the day in a meeting room with some co-workers, discussing <strong>very secret things</strong>, while my phone charged at my desk, a few meters away. Surely, in this day and age, my watch can tell me if it’s done yet, right?</p><p>I did zero research. I bet there’s watch faces, and watch apps, and all sorts of tools that could solve the problem for me. But I just looked at my watch and I couldn’t figure out a way to see it. And that’s when I finally had an idea for something to code on Android Wear.</p><p><strong>TL;DR</strong> — If you’d rather not read all the words I wrote, and would rather see the code I wrote, check out <a href="https://github.com/brendan-fahy/wattsapp">the repo on my github</a>.</p><h3><strong>A New Idea has Entered the Game!</strong></h3><p>I wanted something to show on my watch when my phone was charging, which showed the charge level of the device as a percentage, and was updated periodically. The <a href="https://developer.android.com/design/wear/creative-vision.html">Creative Vision for Android Wear</a> says its experiences should be:</p><ul><li>Automatically launched</li><li>Glanceable</li><li>All about suggest and demand</li><li>Zero or low interaction</li></ul><p>I’ve always thought this could be summed up as: “Notifications. Just do notifications. Properly.”</p><p>The mirroring of notifications from my phone to my watch is about 90% of the value I get from it. The other 10% is in context-specific use cases: handy controls for <a href="https://play.google.com/store/apps/details?id=com.google.android.music">Google Play Music</a>, <a href="https://play.google.com/store/apps/details?id=au.com.shiftyjelly.pocketcasts">Pocket Casts</a>, and <a href="https://play.google.com/store/apps/details?id=com.fitnesskeeper.runkeeper.pro">Runkeeper</a>. I think I can count on one hand the number of times I’ve gone swiping through the interface to launch an app or send a message — and even less times when I’ve used voice input. And I reckon every one of those instances was when I was demoing that functionality to someone who’d never seen a smartwatch before.</p><p>So all I wanted was a notification on my phone. Cool, those are easy, the <a href="https://developer.android.com/reference/android/app/NotificationManager.html#notify%28int,%20android.app.Notification%29">NotificationManager</a> is my friend. What about responding to and reading battery-charging events? That’s easy too, there’s a handy article on the <a href="https://developer.android.com/training/monitoring-device-state/battery-monitoring.html">Android developer docs</a> about it. What about scheduling a task to update the notification once we’d created it?</p><p>There are multiple ways to set up a repeating task in the background, like <a href="https://developer.android.com/reference/android/app/job/JobScheduler.html">JobScheduler</a> and <a href="https://developer.android.com/reference/android/app/AlarmManager.html">AlarmManager</a>. There’s other tools too, like <a href="https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmNetworkManager">GcmNetworkManager</a>, which has a confusingly network-and-GCM-centric name, and straight-up Services were never much fun for me. Evernote released their own library, <a href="https://github.com/evernote/android-job">android-job</a>, that allows you to get on with coding and not worry about which mechanism is being used under the hood. But I was all fired up and enthusiastic, and I’d used JobScheduler once before on a little project, so I went with that. It’s the latest cool new toy for scheduling background jobs! It’s supposed to be great! It’s the way forward for Android! And hey, I didn’t want have to go read a bunch of documentation!</p><p>So I chose to use JobScheduler, and immediately had to go read a bunch of documentation. It was added in API 21, Lollipop. That’s OK, my phone runs Nougat (API 25), so we’re all good. JobScheduler allows us to leverage the operating system’s intelligence to decide when to run our jobs, batching them appropriately, in order to minimise operational costs to the device. This rang a couple of bells in my head, since I only wanted my job to run when my phone was charging anyway, so any potential impact on the battery wasn’t a problem (unless it was huge). I didn’t have to worry about the consequences of waking up the CPU unnecessarily. But I forged on ahead anyway (this is commonly known as <a href="https://en.wikipedia.org/wiki/Foreshadowing">foreshadowing</a>).</p><h3>“Watts App” — The Implementation</h3><p>The app I built is very, very simple. It’s written in Kotlin, because Kotlin is awesome and the semi-colon key on my keyboard is broken. I decided to call it “Watts App”, because it was about charging my battery and I don’t understand how electricity works.</p><p>The app contains:</p><ul><li>An AndroidManifest,</li><li>A BroadcastReceiver which gets called anytime the phone gets plugged in or out,</li><li>A JobService which gets scheduled if it was an ACTION_POWER_CONNECTED event or cancelled if it was an ACTION_POWER_DISCONNECTED event</li><li>And a single Activity, which is really only there for debug purposes. I’d never made an app without an Activity before. It felt weird.</li></ul><h3>Declaring the BroadcastReceiver</h3><p>The first thing to do with a BroadcastReceiver is register it in your manifest file. Well, second thing — you need to decide on a name for it first. I took “inspiration” from <a href="https://developer.android.com/training/monitoring-device-state/battery-monitoring.html">the training article</a> and called mine PowerConnectionReceiver. You need to specify the broadcasts you want it to respond to. In my case, these are the battery charging/not-charging events:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96c69f87e2817ab694452f71baf73f5c/href">https://medium.com/media/96c69f87e2817ab694452f71baf73f5c/href</a></iframe><p>You’ll notice there’s a third intent-filter action added here, named brendan.wattsapp.debug. While working out the kinks in the code, it was frustrating to have to rely on plugging the phone in and out to make things happen — especially given that unplugging the phone severs the ADB connection, and therefore any debugging or logging.</p><p>Side note: I was about to write, “Yes, I know wireless ADB exists, but you need root for that, and this is the first reason I’ve had to root a phone in years” and then I decided to Google it to back up my assumption, and found that the<em> very first</em> result is an app called <a href="https://play.google.com/store/apps/details?id=za.co.henry.hsu.adbwirelessbyhenry">ADB Wireless (no root)</a>, so I’m feeling rather silly right now.</p><p>You can trigger a BroadcastReceiver directly by broadcasting an Intent with the same action as the one you defined in the manifest file. So I added a Button to my MainActivity, and had the button call:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5a2d9f9130e2ad1b47fba7bb0200f76/href">https://medium.com/media/c5a2d9f9130e2ad1b47fba7bb0200f76/href</a></iframe><p>And then I had a handy way to hit my BroadcastReceiver without having to unplug my phone!</p><h3>Writing the BroadcastReceiver</h3><p>The onReceive method of your BroadcastReceiver receives the Intent used to trigger it, as a parameter. According to the training article, you can use this to extract the current charging state and method.</p><p>This didn’t work as advertised for me. If someone can point out a mistake, I’d be glad to learn where I went wrong. Guided by the article, I tried:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7862ab4077777a043e3cdc02181af913/href">https://medium.com/media/7862ab4077777a043e3cdc02181af913/href</a></iframe><p>isCharging, isUnknown and hasBeenDisconnected all came out of this false for me. status was -1, the default value if BatteryManager.EXTRA_STATUS didn’t match an int extra. ¯\_(ツ)_/¯</p><p>Luckily, you can register a null BroadcastReceiver with an IntentFilter for Intent.ACTION_BATTERY_CHANGED any time you want, and this immediately returns an Intent with the latest battery state. I modified my PowerConnectionReceiver to ignore the Intent passed as a parameter to onReceive and request one from the system.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a712f85371b3ae8a3ac2073d8ad2525/href">https://medium.com/media/4a712f85371b3ae8a3ac2073d8ad2525/href</a></iframe><p>My status was now showing meaningful values. Once I knew whether the phone had been plugged in or out, I could decide whether to schedule or cancel my job:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/428aabb7210b42f16d0f4e3b72f4f8a7/href">https://medium.com/media/428aabb7210b42f16d0f4e3b72f4f8a7/href</a></iframe><p>Building the JobInfo object is more interesting:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebfe581d3b47623b1fb22a666548962f/href">https://medium.com/media/ebfe581d3b47623b1fb22a666548962f/href</a></iframe><p>You need to instantiate a ComponentName for the JobService class — the actual work that you want to schedule — and use it to create a Builder for the JobInfo, along with a job ID. The job ID can be used later to cancel a specific job (using JobScheduler’s <a href="https://developer.android.com/reference/android/app/job/JobScheduler.html#cancel(int)">cancel method</a>), or, if on API 24 or above, to retrieve the JobInfo object for a job which has not been executed yet, using <a href="https://developer.android.com/reference/android/app/job/JobScheduler.html#getPendingJob(int)">getPendingJob(jobId)</a>.</p><p>JobScheduler’s power comes from its flexibility. You can build your JobInfo with constraints on available network type, device charging state, timing and scheduling, backoff strategy — I’d highly recommend having a look at <a href="https://developer.android.com/reference/android/app/job/JobInfo.Builder.html">the documentation</a> if you haven’t seen it already.</p><p>For me, I didn’t require a network, required the device to be charging (lol), and wanted the job to run every 60 seconds. Of course, the interval you send to the operating system tells it how often you <em>want </em>it to run the job. The OS reserves the right to do whatever the hell it wants with that information, but it’s nice to express your opinions, even if nobody is listening (see <a href="http://twitter.com/">Twitter</a>, this post, and so forth).</p><h3>Declaring the JobService</h3><p>Like all Service class, your JobService needs to be declared in your AndroidManifest.xml. You need to give it a name, and tell the system it’s allowed to be bound. Here’s mine:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c236fc71311af9b271db99bb65e41cf/href">https://medium.com/media/5c236fc71311af9b271db99bb65e41cf/href</a></iframe><h3>Writing the JobService</h3><p>In my PowerService, I request another Intent with the latest battery state, so I can show a notification with the charge level. (I had a momentary brain-fart trying to figure out where to get a Context on which to call registerReceiver, which made me kick myself and facepalm at the same time, in a new gesture I call the “kickface”. On the plus side, it also led me to <a href="http://stackoverflow.com/a/6446264">the most efficient StackOverflow answer</a> I’ve ever seen.)</p><p>The two important parts of the PowerService are its interaction with the JobScheduler and its use of the NotificationManager.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e40e36d76860e7cfe8f52f619207b4f7/href">https://medium.com/media/e40e36d76860e7cfe8f52f619207b4f7/href</a></iframe><p>onJobFinished is a JobService method that must be called in your onStartJob, with the JobParameters which were passed in, and an interesting boolean, needsReschedule. This should be true if the work you wanted to perform <em>failed</em> for some reason. true tells the JobScheduler to start applying whatever back-off strategy you set in the JobInfo in an attempt to successfully complete the job. I like to live dangerously, so I assume that my notification was successfully posted, and return false. The return value of the method is another boolean, which tells JobScheduler whether your job is still doing work on another thread or not. Useful for asynchronous operations, not so much for this case. I return false.</p><p>It’s <em>almost</em> beginning to seem like JobScheduler wasn’t the right tool for the job. <em>Almost</em>.</p><h3>NotificationManager</h3><p><a href="https://developer.android.com/reference/android/app/NotificationManager.html#notify(int,%20android.app.Notification)">NotificationManager’s notify method</a> tells us:</p><blockquote>If a notification with the same id has already been posted by your application and has not yet been canceled, it will be replaced by the updated information.</blockquote><p>So now we know we can spam the notify method with the same notification ID, safe in the knowledge that we’ll only ever have one notification with the most up-to-date information.</p><p>Creating Notifications is a breeze using the Notification.Builder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05bfe664ef82714bf8858700e66477e3/href">https://medium.com/media/05bfe664ef82714bf8858700e66477e3/href</a></iframe><p>The only interesting thing here is the BatteryManager.EXTRA_LEVEL retrieved from the battery status Intent, which gives us the battery level as an integer between 0 and 100, and the setOnlyAlertOnce(true) method on the Builder. I want a notification I can look at, but I don’t want the updates bothering.</p><p>But honestly, I’m not too familiar with this API. I think you need to manually setLights, setSound, and setVibrate if you want those things anyway, which I’m not doing, so there’s a good chance I can do without this method.</p><p>And that’s pretty much it! In onStopJob, I clear out the notification with notificationManager.cancel(NOTIFICATION_ID). Here’s how it looks in action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IB7jBlP3AL3rrI7Bj3o33g.jpeg" /><figcaption>National Geographic here I come</figcaption></figure><p>So there we have it! My first watch app, and I didn’t write a single line of code that had anything to do with Android wear! A notification that gets updated with the latest battery level every sixty seconds or so, and gets cleared when the phone is unplugged. Right?</p><h3>JobScheduler is a harsh mistress</h3><p>From onStopJob:</p><blockquote>This method is called if the system has determined that you must stop execution of your job even before you’ve had a chance to call <a href="https://developer.android.com/reference/android/app/job/JobService.html#jobFinished(android.app.job.JobParameters,%20boolean)">jobFinished(JobParameters, boolean)</a>.</blockquote><p>So this will only work if the phone gets unplugged in the time between onStartJob being called and it calling jobFinished. This is extremely unlikely to ever happen.</p><p>I was very excited the first time I ran the app. This was before I’d added my handy debug button in MainActivity, so I unplugged the phone, re-plugged it in again to trigger the BroadcastReceiver, and sat back to wait for my notification to show up. The interval for the job was set to 60 seconds, so I shouldn’t have to wait long. After much waiting, and unplugging, and re-plugging, and waiting again, I noticed this in the Logcat output:</p><pre>brendan.wattsapp W/JobInfo: Specified interval for 123 is +1m0s0ms. Clamped to +15m0s0ms`</pre><p>JobScheduler gets to make its own mind up about when to run your job — that’s part of the point. But I’d expected this to be pretty inconsequential for lax parameters like mine. This log makes it look like I have a 1500% multiplier on my interval to look forward to. What gives?</p><h3>Nougat is also a harsh mistress</h3><p>I’m not the first person to notice this. I found <a href="http://stackoverflow.com/questions/38344220/job-scheduler-not-running-on-android-n">an explanation on StackOverflow</a>. As of Nougat, this tidbit appears in the documentation for JobInfo.Builder.setPeriodic’s intervalMillis parameter:</p><blockquote>long: Millisecond interval for which this job will repeat. A minimum value of <a href="https://developer.android.com/reference/android/app/job/JobInfo.html#getMinPeriodMillis()">getMinPeriodMillis()</a> is enforced.</blockquote><p>getMinPeriodMillis apparently returns fifteen minutes. You can usesetOverrideDeadline and force the job to run — but a job can’t be both periodic and override the deadline.</p><h3>Conclusion</h3><p>This was a lot of fun. I wrote the first version of Watts App in a couple of hours after work earlier this week, and by the time I finished, it was mostly working. <a href="https://www.youtube.com/watch?v=B436avtEXzs">Mostly</a>.</p><p>The notification only updates every fifteen minutes or so. That’s workable, but it’s not what I wanted. I added a really hacky line to my PowerConnectionReceiver to cancel the notification when it was stopping the job:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55d7e14f2b49e8591bcac1a03383f5de/href">https://medium.com/media/55d7e14f2b49e8591bcac1a03383f5de/href</a></iframe><p>So now at least it goes away automatically. But it’s clearly the wrong way to achieve that result.</p><p>One idea to improve things is to schedule two jobs: one with setOverrideDeadline set to something very small, to show the first notification, and a second like the one above, to update periodically. Another, probably smarter idea, is to use the AlarmManager to show and update the notification instead. The caveats of AlarmManager are things like “it‘s not as responsible/efficient as JobScheduler” and “it doesn’t persist across reboots”, but they don’t matter to this particular use case. And I’ve never used it before. So I’ll probably try that.</p><p>Another foible of the current implementation is that the notification will show on the phone as well. That’s not really a problem, but it is a bit pointless. You can build a notification to be local-only — that is, to show only on the device that created it. So I can easily make this notification only show on my phone, and not on my watch, but that’s the opposite of what I want. to make it show on the watch, and not on the phone, I’ll have to write an Android Wear app, and create my local-only notification from there. I think.</p><h3>Even More Conclusion</h3><p>Writing this blog post was also a lot of fun. I’ve never written a technical blog post before. If you’ve read this far, thank you, and I hope you enjoyed it. There will be a follow-up to this post, hopefully sometime soon. In the meantime, I occasionally say things on <a href="https://twitter.com/brendan_fahy">Twitter</a> and help organise the <a href="https://www.meetup.com/Dublin-Android-Developer-Meetup/">Dublin Android Developer Meetup</a>.</p><p><a href="https://github.com/brendan-fahy/wattsapp/releases/tag/jobscheduler">The wattsapp repo is located on my github.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fea7e293995" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>