<?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 Lisa Watkins on Medium]]></title>
        <description><![CDATA[Stories by Lisa Watkins on Medium]]></description>
        <link>https://medium.com/@lisamariewatkins?source=rss-95f8e32d856b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*d0R1wA136gB_nTX3pyuRhA.jpeg</url>
            <title>Stories by Lisa Watkins on Medium</title>
            <link>https://medium.com/@lisamariewatkins?source=rss-95f8e32d856b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 22:46:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lisamariewatkins/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 Case for Single Activity Android Apps]]></title>
            <link>https://medium.com/code-with-lisa/the-case-for-single-activity-android-apps-26bc7562289c?source=rss-95f8e32d856b------2</link>
            <guid isPermaLink="false">https://medium.com/p/26bc7562289c</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Lisa Watkins]]></dc:creator>
            <pubDate>Thu, 11 Feb 2021 21:00:30 GMT</pubDate>
            <atom:updated>2021-02-11T21:00:30.673Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*69yiAj0kQXKAkesZH4Egiw.jpeg" /></figure><p>Whether you have already adopted single Activity architecture in your Android apps or not, it can be a useful exercise to remind ourselves why this pattern works. To keep things interesting, I’d like to dig a little bit deeper than “because Google said so,” which they did (at Google I/O in 2018).</p><p>Before digging in, what is single Activity architecture? As the name suggests, your app has one activity (usually called MainActivity). It’s important to note that this Activity is as lean as possible and completely devoid of business logic. Each individual screen in your app is then represented by a Fragment or a custom View. Newer Android API’s have been built to support this architecture, including the new <a href="https://developer.android.com/guide/navigation/navigation-getting-started">Navigation Component</a>.</p><p>So why only one Activity? Android Activity’s are one of the four Android app components. Although historically this hasn’t been enforced, philosophically speaking, an Android app component exists <em>as an entry-point</em> to your application. An Activity’s siblings include Broadcast Receivers, Services, and Content Providers. All of these app components must be registered in AppManifest.xml. With this observation alone, it’s probably feeling intuitive that every screen in your app does not need to be represented by an Activity, but let’s keep digging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*68Dzf9MOUvXxyGbpdJYkmw.png" /></figure><p>The logical direct parent of the four app components is the application itself. This application level is the most global scope you can reach in your Android app. Dependencies provided at this level are global to all other instances in your application. This means that if you have multiple Activity’s that each represent a different screen in your app, any shared data would have to be made available to this global scope. Not only do your Activity instances have access to this scope, but so do Broadcast Receivers, Services, and Content Providers. This violates a golden rule in Software Engineering, simply put, “Avoid global state.” Furthermore, if you have a single Activity, the Activity scope becomes a useful, more contained scope for containing dependencies that need to be shared across all UI code. The same Activity context can also be used across all screens in your application with a single Activity architecture, avoiding unintended bugs.</p><p>We see this issue of global state manifest in how Google developed architecture component API’s. Let’s take a look at <a href="https://developer.android.com/topic/libraries/architecture/viewmodel">ViewModel</a>.</p><p>If you use ViewModel’s in your Android app, you probably know that ViewModel instances can be shared between Fragments, but not between Activity’s. Simply put, ViewModel instances can be used to share data between Fragments but not between Activity’s. But, why?</p><p>If you don’t know how ViewModel functions underneath the hood, I recommend setting some breakpoints in lifecycle methods and exploring. To loosely summarize, ViewModel instances are stored in a data structure. When an Activity or Fragment is destroyed, perhaps by rotating the device, the system checks this data structure for an existing instance of the ViewModel. The ViewModel instance is retained and any state owned by the ViewModel is restored.</p><p>In the case of an Activity, the owner of the data structure where the instance of ViewModel is preserved is the Activity itself. For Fragments, the owner of the data structure is the FragmentManager. When the Activity is destroyed, so is the data structure that contains the ViewModel instance, and therefore the ViewModel is also destroyed. When the Fragment is destroyed, the FragmentManager lives on, and therefore the ViewModel also lives on.</p><p>If you think about the way ViewModel is implemented, it makes sense! Having ViewModel instances saved at the Application scope level would be <em>too</em> global and expose ViewModel instances to the entire dependency graph of your application. The implementation of ViewModel clearly lends itself to a single Activity, multi-fragment architecture and is symptomatic of the Application scope simply being too large.</p><p>There are other Android API issues with multi-Activity architecture, such as transitions. Because Activity’s are part of the Android framework, new features aren’t always back-ported seamlessly. We can see this with glitchy transition animations. The most obvious issue reported is a glitchy status bar when navigating between two Activity’s, shown below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FyAbDPjhftlQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DyAbDPjhftlQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FyAbDPjhftlQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbe697e2747d147db1971eca227a4de3/href">https://medium.com/media/dbe697e2747d147db1971eca227a4de3/href</a></iframe><p>We can also see problems with multi-Activity architecture manifest in third party libraries. Let’s talk about Glide.</p><p>Glide is a powerful image loading library widely used in Android development. Glide smartly caches images in memory to improve rendering speed and user experience. A common OOM exception occurs when you use Glide in a multi-Activity apps. If you load an image in memory in an Activity, Glide will not release that image from memory until that Activity is destroyed. If you have several Activity instances on the backstack, you end up consuming a lot of memory for all of the stale bitmaps that Glide has loaded in memory, which can result in an OOM exception.</p><p>This example is not necessarily a symptom of the global state issue, but would be avoided if your app adopted the single Activity philosophy adopted by others in the Android community. And its true, you could clean up bitmaps in memory through lifecycle hooks like onStop(). However, adopting a single Activity architecture would allow you to do any necessary clean up at the Activity scope and not the global Application scope!</p><p>Whether you are still using multiple Activity’s or you’re already a single Activity architecture convert, I hope the exercise of exploring the “why” behind single Activity apps was worth your while. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26bc7562289c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-lisa/the-case-for-single-activity-android-apps-26bc7562289c">The Case for Single Activity Android Apps</a> was originally published in <a href="https://medium.com/code-with-lisa">Code With Lisa</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[9 Common Android Interview Gotchas]]></title>
            <link>https://medium.com/code-with-lisa/9-common-android-interview-gotchas-8afb8a1299f3?source=rss-95f8e32d856b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8afb8a1299f3</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[interview-tips]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Lisa Watkins]]></dc:creator>
            <pubDate>Sat, 23 Jan 2021 03:13:16 GMT</pubDate>
            <atom:updated>2021-01-29T18:15:48.863Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*OM42T0Eo0irftsJYxKcSgA.png" /></figure><p>So you’ve landed an Android interview! Congratulations. Let’s get to work and set you up for success for your upcoming phone screen or (perhaps virtual) on-site.</p><p>I usually interview Android candidates at least once a week, which means I’ve talked to a lot of candidates over the years. I see similar knowledge gaps pop up again and again, and I’m hoping this list can help guide you on what topics to review before the big day.</p><p>First, let’s talk about the common structure of Android interviews. Some companies value core computer science concepts as well as Android expertise. Some companies don’t care to quiz you on computer science concepts at all. Usually, in addition to Android and computer science, there is a behavioral portion of your interview where you’ll have a chance to talk about your past projects and experience. Talk to your recruiter or hiring manager for details so you can best prepare for your interview. This article only addresses the Android portion of your interview.</p><p>For Android interviews, the structure will vary by company but the general idea falls into two categories: project-based interviews and coding challenge interviews.</p><p>In project-based interviews, you guessed it, you build a project. Sometimes, you design the project from a high level and sometimes you’re expected to provide working code for the project. The most common project that you’ll see in an Android interview is displaying a list of data (it’s always a safe bet that you will be using a <em>RecylerView</em> in the interview, so brush up on the ins-and-outs). This is a super popular interview project for a reason. If you think about it, most of your favorite apps do nothing more than display a list of data (think social media news feeds, grocery lists, retail apps, etc). A good exercise to come into a project-based interview well-prepared is to go through your top 5 favorite apps on your phone and think about how you would design/implement them.</p><p>In coding challenge interviews, you are usually tasked with a “challenge” where you build a feature. Common tasks include creating a screen that takes and sends an image, displaying a list of data (again), or sharing location with another user. You should know the basics around how to accomplish these tasks in Android, but don’t waste time memorizing every detail of every Android or third party API. You can usually look up API specifics or ask your interviewer for help. If you’re expected to have every public method on <em>RecylerView</em> memorized, it’s probably not a well-designed interview.</p><p>Now that we’ve covered some Android interview basics, let’s dive in.</p><h4>1. Solve problems with an architecture-oriented mindset.</h4><p>This list isn’t necessarily ordered, but this is definitely number one by design. Write code as if you would be submitting a pull request to master. Don’t litter your Fragment or Activity class with business logic! Pick an architecture pattern that you’re comfortable with, and use it. When you’re preparing for the interview, always use your architecture pattern to solve common tasks.</p><p>For example, let’s say your interview coding challenge expects you to display some text on the screen after a user clicks a button.</p><p>You could write something that “just works”, like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e3428fa098924db7b30b47610e049e7/href">https://medium.com/media/4e3428fa098924db7b30b47610e049e7/href</a></iframe><p>This is fine, but this isn’t great. You missed out on an opportunity to demonstrate that you know how to write production-ready Android code.</p><p>This is much better:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf556ee6b14783910ec736b8c0eb8286/href">https://medium.com/media/cf556ee6b14783910ec736b8c0eb8286/href</a></iframe><p>Wow, you’ve just gone from “just works” to “great”! You’ve taken the opportunity to demonstrate your knowledge of industry best practices and you’ve wow’ed your interviewer. You can also mention all the “why’s” behind choosing MVVM over other architecture patterns like MVP or MVC. You can mention all the fabulous unit tests you would write, or even write them if time permits.</p><p>I know this example was simple, but stay on your toes during your interview when it comes to the design and architecture behind your code. A really common pitfall here is saving state. Beware of saving any state inside of a Fragment or Activity, and be wary of <em>how</em> you’re storing state. Use Kotlin data classes for data modeling (please do not use a boolean or a String). Remember, if you wouldn’t submit this code in a PR, its not good enough to submit during an interview!</p><h4>2. Use ViewModel correctly.</h4><p>It’s a really unfortunate mistake that I see way too often. You’ve remembered the first item on this list and you’ve got your chosen architecture pattern DOWN. You have opted to apply MVVM and use a ViewModel to store data for your Fragment or Activity, wonderful! But… you’ve made a mistake.</p><p>Can you spot the issue with this code?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef0094b1e7e289de4c125f1d601b8f2e/href">https://medium.com/media/ef0094b1e7e289de4c125f1d601b8f2e/href</a></iframe><p>What happens when the user rotates the screen? The instance of our ViewModel is preserved, sure. But did we make any wins on our network usage? No. We call the network again and again every time <em>onCreate()</em> is called.</p><p>How do we fix this? Cache the response data we need in our instance of LiveData and move the network call into our ViewModel’s <em>init()</em> method. That way, we don’t couple our network usage to our Activity’s <em>onCreate()</em> and we can leverage our retained ViewModel instance properly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0bdbcd5218ad76582497bb6d4c0e999/href">https://medium.com/media/d0bdbcd5218ad76582497bb6d4c0e999/href</a></iframe><p>Beautiful!</p><h4>3. Stick to the problem at hand.</h4><p>This manifests in a couple different ways. It can get you in trouble, especially with time, if you broaden your focus too much on <em>what</em> you’re building and <em>how</em> you’re building it. Let me explain more.</p><p>It’s a <em>good </em>thing to be product-oriented! In fact, it is a great thing, especially as a mobile developer. However, it’s best to be product-oriented <strong>and</strong> focused on the task at hand. If you’re asked to build an app that displays a list of “to-do” items to a user, it shows a healthy and desirable product mind-set if you mention cool additional features for this app like location-based reminders or notifications. As you’re coding, mention ideas if they come to mind — but make sure that you finish the assignment at hand before diving into extra features.</p><p>Most companies will grade you objectively on how far along you can get in the assigned project or coding challenge. These are typically associated with numerical scores, and you won’t pass the interview unless you reach a certain score. You need to be mindful of your time and complete as much of the assigned task as you can. Once you’re done with the objective, ask your interviewer if they want you to write tests. If not, go ahead and add the cool extra stuff.</p><p>This also comes up with extra libraries, namely Dagger or Hilt for dependency injection or new Architecture Component libraries. If you’re aware of these things, great! Mention them — but don’t spend precious interview minutes on implementing these extras if you do not have a finished product. They won’t count for much if you haven’t already completed the task your interviewer has asked for.</p><h4>4. Stick to the language you’re comfortable with.</h4><p>You usually have two (practical) choices for most Android interviews: Kotlin and Java. Kotlin is the shiny new-new, so it’s tempting to use Kotlin even if you’re not comfortable with it. RESIST THE TEMPTATION. Using Kotlin when you don’t know the ins-and-outs of the language will hurt you more than help you. Just use Java if that’s what you’re used to! I would also argue that it is a poor interview design if using Java would be counted against you. Kotlin is still reasonably new on the scene, especially if you’re a new university grad.</p><p>The problem with using Kotlin when you’re more comfortable with Java is that, <strong>spoiler alert</strong>, it’s super obvious to your interviewer. Kotlin is an incredible language, but there’s a lot of Kotlin language paradigms that you have to know well to use the language effectively for Android. If you’re new to Kotlin, I recommend reading <a href="https://www.manning.com/books/kotlin-in-action">this book </a>cover-to-cover to equip you with the ins-and-outs that will most likely come up in interviews if you choose to code in Kotlin.</p><p>What if you are comfortable in Kotlin, but you’re not an expert? That’s ok, just do not use Kotlin language features that you’re not familiar with. Don’t use the <em>in</em> or <em>out</em> modifiers if you don’t know what they do! Don’t use the <em>by</em> keyword if you don’t know how it works! If you’ve been using data classes for your API responses, be prepared to answer in-depth questions about data classes! Read up on these things if you’re not familiar.</p><p>If any Kotlin language feature is a mystery to you, demystify it and become an expert. This will set you up for success if you’re interviewing in Kotlin.</p><h4>5. Stick to the libraries you’re comfortable with.</h4><p>Following the same logic as our Java vs. Kotlin discussion, do not use a library in your interview project or coding challenge that you do not know well.</p><p>Adding Dagger to your project when you can’t speak to how Dagger generally works behind the scenes or why it’s better than DIY dependency injection is not a good idea. When you add a library to your project or reference it in your coding challenge, you are serving up the library to your interviewer as fair game for questions. It would be better to simply avoid adding the library than add it and not be able to explain your “why” behind using it.</p><p>Before your interview, it would be good to look at common Android libraries, pick the one you’ll use for an interview and make sure you can speak to why you chose it as opposed to other available libraries.</p><p>Using Glide for loading images in your interview photo app? Great! Make sure you can state exactly why you’re not using Picasso. How do both compare when it comes to image caching? What about the library size of each?</p><p>Are you using Hilt for dependency injection? Amazing! You should be able to tell the interviewer why you’re not using Dagger.</p><p>Remember our discussion about sticking to the task at hand? All of these libraries are “extras”. It usually is not criteria for an Android role that you know exactly how Dagger works underneath the hood. If you use Dagger in an interview, <em>know</em> Dagger. If you don’t, just skip it. Only use these libraries if they can demonstrate your strengths, not point out a weakness or a gap in knowledge.</p><h4>6. Think about error states.</h4><p>This comes up a lot. It’s an easy opportunity for an interviewer to poke holes in your code.</p><p>A good mobile developer knows to proactively handle bad network connectivity. If one of the requirements for your interview prompt has anything to do with a network connection, <strong>do not</strong> forget to handle error states. After you’ve gotten a first draft of your networking code out in the IDE or on a whiteboard, the immediate next step you should take is verbally point out potentials for network errors and address them with code. This shows attention to detail. Make sure to also run through scenarios where perhaps a user rotates the screen mid-network request. Don’t forget to call out common threading “uh oh”’s here.</p><p>A good mobile developer also knows how likely it is for their app to be killed in the background after the user answered a phone call mid-scroll or switched to a messaging app to reply to a text. Look for these common mobile edge cases, call them out, and if you have time — address them!</p><h4>7. Write code for BILLIONS.</h4><p>This item won’t always necessarily count against you, especially for more junior roles. However, what sets Android software engineering apart from other disciplines is that Android runs on all kinds of devices in all kinds of places.</p><p>Android runs on mobile phones, and Android runs on refrigerators. Android runs on 5G network connections, and Android runs on… way slower network connections. <a href="https://developer.android.com/docs/quality-guidelines/build-for-billions/data-cost">Did you know that data plans in some countries can cost 10% of a user’s monthly income?</a> It will set you apart in an interview if you demonstrate Android app design skills with a “code for billions” mentality.</p><p>Familiarize yourself with proper architecture patterns to support users with low-end devices on slow networks. For example, if your interviewer asks you to build an instagram-like app, you should proactively call out things like image resolution and image caching. Would you check for network connection quality before asking the server for a high-resolution image? If you need to perform some long running background task to download these images, how would that impact battery usage?</p><h4>8. Don’t over-index on performance concerns.</h4><p>After the previous item on this list, it might confuse you that I would tell you “code for billions, but at the same time, don’t care TOO much about performance”! Let me explain.</p><p>It’s reasonable for you to call out that you’ll use WorkManager to schedule long-running background tasks when the user is connected to WiFi and the device is connected to a charger because you are concerned about performance. It is not as reasonable for you to say that you’re going to avoid allocating a Enum variable in your MainActivity and sacrifice readability for the memory allocation cost of an Enum.</p><p>In the days of Dalvik and the days before Dalvik, it was probably more reasonable for you to worry about Enum objects in regards to memory allocation or maybe even pool objects in memory (gasp!). We could go over all of the details about improvements Google has made to the Android runtime, but let’s save that for another blog post.</p><p>Long story short, don’t sacrifice minuscule performance gains for clean, readable code in your interviews in the name of performance.</p><h4>9. TALK. Yes, talk out loud!</h4><p>This is a big one, and doesn’t come naturally for everyone (especially me!) — but allow me to let you in on a little secret.</p><p>The <em>more</em> you talk, the <em>more</em> your interviewer can understand your thought process, and the <em>more </em>you will gain points for team-work and collaboration. Even better — if you’re pressed for time and can’t get to some of the extra stuff like writing unit tests, using fancy libraries, or adding error states simply mentioning these things will demonstrate that you’re at least thinking about them! What might seem obvious to you is not always obvious to all candidates, so think out loud and let your interviewer know exactly what’s going through your mind.</p><p>Especially if this does not come natural for you, practice! When preparing for your interviews, say your thoughts out loud as you practice coding. Get used to thinking out loud! Trust me, this will only help you.</p><p>—</p><p>I hope this list was helpful, and please drop a comment if you have questions or feedback. Good luck interviewing, and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8afb8a1299f3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-lisa/9-common-android-interview-gotchas-8afb8a1299f3">9 Common Android Interview Gotchas</a> was originally published in <a href="https://medium.com/code-with-lisa">Code With Lisa</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JUnit 5 and Android Architecture Components]]></title>
            <link>https://medium.com/code-with-lisa/2-minute-time-saver-junit-5-and-android-architecture-components-94312478cd44?source=rss-95f8e32d856b------2</link>
            <guid isPermaLink="false">https://medium.com/p/94312478cd44</guid>
            <category><![CDATA[architecture-components]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[junit-5]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Lisa Watkins]]></dc:creator>
            <pubDate>Wed, 27 Mar 2019 00:58:57 GMT</pubDate>
            <atom:updated>2019-04-01T22:42:10.461Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BCNbly8t56zahpWpwbryTA.jpeg" /></figure><p>Oh, JUnit tests. I’ve grown quite stubborn to insist on writing JUnit tests over Instrumentation tests (when possible, and when reasonable). If you’ve developed a few Android applications, we probably have this in common.</p><p>It’s an exciting time for Kotlin developers to adopt <a href="https://junit.org/junit5/docs/current/user-guide/">JUnit 5</a>. Here’s a brief, and probably <strong>NOT</strong> all-inclusive list:</p><ul><li>JUnit 5 has added advanced assertions for working with lambdas</li><li>You can now specify to only create <strong><em>ONE</em></strong><em> instance of the test class per test method</em> (this one particularly excites me, I could shout it from the mountain top)</li><li>You can now “nest” test methods that make sense together with the @Nest annotation</li></ul><p>If you’re not already using JUnit 5, maybe my brief list just convinced you to give it a shot. Great! Let’s talk more about the architecture of your app. Are you using <a href="https://developer.android.com/topic/libraries/architecture">Android Architecture Components</a>? Maybe <a href="https://developer.android.com/topic/libraries/architecture/livedata">LiveData</a>?</p><p>The following test method is verifying that PetRepository#nextPet() is grabbing a LiveData object that contains a Pet I retrieved from the network. (Oh yeah, if you haven’t heard, I’m building an app called <a href="https://github.com/lisamariewatkins/Pawsitive-android">Pawsitive</a> — so I talk about dogs and cats and animals a lot in the blog.)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc53e63995079f50211852aea23dfef9/href">https://medium.com/media/fc53e63995079f50211852aea23dfef9/href</a></iframe><blockquote>Side bar: I’m also using <a href="https://mockk.io/">Mockk</a> and <a href="https://kotlinlang.org/docs/reference/coroutines-overview.html">Kotlin Coroutines</a> and lots of fun stuff but you’ll have to check out a different article (coming soon!) for more details on that.</blockquote><p>To recap, in this test I am concerned about making sure that my LiveData object has what I expect it to have. I am using observerForever{..} so that I can subscribe to the LiveData object captured in result.</p><p>This seems fine, until —</p><pre>java.lang.RuntimeException: Method getMainLooper in android.os.Looper not mocked. See <a href="http://g.co/androidstudio/not-mocked">http://g.co/androidstudio/not-mocked</a> for details.</pre><pre>at android.os.Looper.getMainLooper(Looper.java)</pre><p>Oof. I’m in a JUnit test! This is bringing back nightmares of “Tests I’ve Struggled Writing Before” past. Of course, the JVM doesn’t know anything about the main thread (or any other Android dependency for that matter).</p><h3>I promised you this 2 minute read would save you some time — so here it is…</h3><p><strong>Step 1: </strong>Add this dependency to your app’s build.gradle:</p><p>testImplementation “android.arch.core:core-testing:$version”</p><p><strong>Step 2: </strong>Now, write this Kotlin extension. Stick it somewhere that makes sense in your test package.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7f43ce61df753e31f8cb62e02ce81d1/href">https://medium.com/media/c7f43ce61df753e31f8cb62e02ce81d1/href</a></iframe><p><strong>Step 3:</strong> Add this line above your test class:</p><pre>@ExtendWith(InstantExecutorExtension::class)</pre><blockquote>If you came to this article to just catch a fish, you can stop reading right here. If you came to this article to <em>learn</em> to fish, keep reading for a “why” behind this fix.</blockquote><p>So, why did this exception happen in the first place? If you’re new to Android development, I’ll just give you a quick review.</p><p>LiveData has some methods that make assertions you are running on the main thread. This is needed for Android world, but if you’re running JUnit tests with only the JVM, this check is going to result in a crash. We don’t have any knowledge about android.os.Looper in the JVM. This means that somehow we must figure out how to interact with LiveData without using the main thread.</p><p>The architecture components team was kind enough to provide a way to do this — with ArchTaskExecutor.</p><p>If we were using JUnit 4, we would have simply added a Rule to our test class. The reason that we had to make this Kotlin extension with JUnit 5 is because JUnit 5 bundled up the concept of Runner, TestRule, and MethodRule all under one API called <a href="https://junit.org/junit5/docs/current/user-guide/#extensions">Extension</a>. Extensions are registered with a class much like JUnit 4 Runners — with a class annotation. This annotation is @ExtendWith(...) .</p><p>The extension we added above sets a TaskExecutor delegate on ArchTaskExecutor.</p><p>Check out this line from the code above:</p><pre>override fun isMainThread(): Boolean = true</pre><p>We are simply faking out that we are on the main thread. We set this delegate before each test runs, and then we clean it up right after to avoid any unintended side effects.</p><p>No magic, just some fish. Err — code.</p><p>As always, happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94312478cd44" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-lisa/2-minute-time-saver-junit-5-and-android-architecture-components-94312478cd44">JUnit 5 and Android Architecture Components</a> was originally published in <a href="https://medium.com/code-with-lisa">Code With Lisa</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dagger.android — The Missing Deep Dive]]></title>
            <link>https://medium.com/code-with-lisa/dagger-android-the-missing-deep-dive-96ec4f4c7d01?source=rss-95f8e32d856b------2</link>
            <guid isPermaLink="false">https://medium.com/p/96ec4f4c7d01</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[dagger-2]]></category>
            <dc:creator><![CDATA[Lisa Watkins]]></dc:creator>
            <pubDate>Sat, 09 Mar 2019 18:05:53 GMT</pubDate>
            <atom:updated>2019-03-09T18:06:10.712Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dagger.android — The Missing Deep Dive</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*deFmgx7kHmRvE7Uz2teYOg.jpeg" /></figure><p>I know what you’re thinking — not another Dagger article. There are a ton of great resources out there that explain the basics of dependency injection with Dagger. This article is not one of those. I’m going to assume that you are familiar with Dagger, and I’m also going to assume that you’ve probably used Dagger in one of your applications.</p><p>The fundamental problem with Dagger and Android applications is that without Dagger.android , any Android component that you want to inject has to know about how it is injected. We get a lot of code like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*v11xyMTVMLRX-qT5DLzxpg.png" /></figure><p>Yuck, this definitely violates a major principle of dependency injection: a class should never know about how it is injected.</p><p>This is why I want to specifically talk about Dagger.android and why, after working with Dagger in my projects for over a year, I feel as though I’ve finally seen the light. This is how Dagger is <em>supposed </em>to look and feel with your Android projects.</p><p>First things first, lets define our ApplicationComponent and ApplicationModule.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/340493350ef4d2cd2af816b80c73569c/href">https://medium.com/media/340493350ef4d2cd2af816b80c73569c/href</a></iframe><p>Notice that the first module included in ApplicationComponent is <a href="https://google.github.io/dagger/api/latest/dagger/android/AndroidInjectionModule.html">AndroidInjectionModule</a>. This module provides the bindings for all Android framework base types (activities, fragments, services, and broadcast receivers).</p><p>In ActivityModule and FragmentModule, notice the annotation <a href="https://google.github.io/dagger/api/latest/dagger/android/ContributesAndroidInjector.html">@ContributesAndroidInjector</a>. This annotation is purely syntactic sugar to bind an <a href="https://google.github.io/dagger/api/latest/dagger/android/AndroidInjector.html">AndroidInjector</a> with the activity or fragment. When you look at the generated code for ActivityModule_ContributesMainActivity, you’ll see a generated map binding with the activity name as the key and a subcomponent that extends AndroidInjector .</p><blockquote>Generated code below:</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fd858b762398d4cdb58ffe538a2fc73/href">https://medium.com/media/7fd858b762398d4cdb58ffe538a2fc73/href</a></iframe><p>When we look at more generated code later, it will become more clear how Dagger is building AndroidInjectors to inject our activities and fragments.</p><p>Now, the real bread and butter of using Dagger.android — our application does not need to know anything about how it is injected. The work can be deferred to ApplicationInjector.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2696db0511e40c6d104acab8ade36c4c/href">https://medium.com/media/2696db0511e40c6d104acab8ade36c4c/href</a></iframe><p>Moving on to our Application class…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6526ee9f185dee89603301d43bdc4a86/href">https://medium.com/media/6526ee9f185dee89603301d43bdc4a86/href</a></iframe><p>As you can see, we’ve implemented HasActivityInjector and we’ve overridden activityInjector() to return an injected instance of DispatchingAndroidInjector&lt;Activity&gt; . When ApplicationInjector builds the application component, you can see that in the generated code we land here…</p><blockquote>Generated code below:</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/975e94c57e85e0c6b9e33e0d4d2a0402/href">https://medium.com/media/975e94c57e85e0c6b9e33e0d4d2a0402/href</a></iframe><p>We’re setting up MainActivity&#39;s subcomponent builder. When ApplicationInjector moves on to inject BaseApplication, we land here…</p><blockquote>Generated code below:</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90934492874a7852e5f0596a0340415c/href">https://medium.com/media/90934492874a7852e5f0596a0340415c/href</a></iframe><p>When we inject BaseApplcation, we also inject its member variables. See getDispatchingAndroidInjectorOfActivity? This is exactly how we inject BaseApplication&#39;s dispatchingAndroidInjector with the proper map. So far we just have one entry, MainActivity and its subcomponent. Now every time we inject an activity in our application, we check for it in dispatchingAndroidInjector to complete the injection.</p><p>Now it is clear that @ContributesAndroidComponent generates a map of our activity classes to their subcomponent builders, which each in turn generate a map of all their child fragments and their subcomponent builders.</p><p>Now, lets take a look at MainActivity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5ae43282e2040cb450576e28803fdac/href">https://medium.com/media/f5ae43282e2040cb450576e28803fdac/href</a></iframe><p>Just how our Application class impelmented HasActivityInjector , our MainActivity class implements HasSupportFragmentInjector. Same exact deal here. Our DispatchingAndroidInjector&lt;Fragment&gt; member variable is injected with the mapping of our fragments to their subcomponent builders.</p><p>Now, all we have to do to inject our activities and fragments is call AndroidInjection.inject(activity) and AndroidSupportInjection.inject(fragment) . Lets check out what AndroidInjection.inject(activity) is doing.</p><blockquote>dagger.android.AndroidInjection</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d70f3c1586ffe092321dd66a647be3c9/href">https://medium.com/media/d70f3c1586ffe092321dd66a647be3c9/href</a></iframe><p>We first make sure that our Application class is an instance of HasActivityInjector — then we call .activityInjector(). Remember we implemented that method in BaseApplication? Here we return the DispatchingAndroidInjector&lt;Activity&gt; instance that has a list of AndroidInjector factories. If we can’t find the mapping, we’ll throw an exception. If all is well and we do find the mapping, we’ll call inject() and our subcomponents factory will handle all member variable injection for our Android component.</p><p>A really nifty way to handle AndroidInjection.inject is to register it in lifecycle callbacks for your application and have your injectable fragments implement an empty interface. I called my empty interface Injectable. Check out an updated version of ApplicationInjector below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e27f3f2c32516c0418fe1112820d779/href">https://medium.com/media/7e27f3f2c32516c0418fe1112820d779/href</a></iframe><p>Now, any time we create a fragment, if it implements Injectable we take care of the injection.</p><p>I hope this article conveys how excited I am to be using Dagger.android in my projects, and why you should too. Hopefully this article also demystified how things are working underneath the hood, and its clear how you can use Dagger.android to inject all your Android components moving forward.</p><p>Thanks for reading, and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96ec4f4c7d01" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-lisa/dagger-android-the-missing-deep-dive-96ec4f4c7d01">Dagger.android — The Missing Deep Dive</a> was originally published in <a href="https://medium.com/code-with-lisa">Code With Lisa</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compose an image “off screen” on Android]]></title>
            <link>https://medium.com/code-with-lisa/compose-an-image-off-screen-on-android-59f87ca04e49?source=rss-95f8e32d856b------2</link>
            <guid isPermaLink="false">https://medium.com/p/59f87ca04e49</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Lisa Watkins]]></dc:creator>
            <pubDate>Thu, 27 Sep 2018 19:01:33 GMT</pubDate>
            <atom:updated>2018-09-27T19:01:33.577Z</atom:updated>
            <content:encoded><![CDATA[<p>There’s a variety of different reasons you’d like to compose an image “behind the scenes” — and its actually quite simple.</p><p>I’ve built a custom view that has a base image and some text layered over it. The image is not stored on the user’s device, but rather on a server somewhere. I’d like the user to be able to click a button and share or save the final composition created by my custom view. The trick here is I would like to do this without visibly drawing my custom view on the screen.</p><p>What makes this tricky? Well, first, I don’t want to just fetch the image. I need to do some stuff with it (i.e. layer some text over it) before I’m ready for the user to share or save it. Also, I don’t have access to the image locally.</p><p>I’ve created a custom view with a few convenience methods to handle fetching the image from the server and then add some text over the image. I’m not going to go into much further detail on my composition for the sake of simplicity. I’ve named my composition class MySecretCompositionView and extended FrameLayout.</p><p>First, create an empty layout file that will house your final composition. This is where I include my custom view. Set the height and width to the height and width (in pixels) of the image. Make sure this view is invisible (not gone).</p><p>In order for the Android OS to draw your composition, it needs to be attached to the window.</p><pre>private void attachToWindow() {<br>    WindowManager.LayoutParams layoutParams = <br>                                   new WindowManager.LayoutParams();</pre><pre>    windowManager = ((WindowManager) context<br>                         .getSystemService(Context.<em>WINDOW_SERVICE</em>));</pre><pre>    windowManager.addView(mySecretCompositionView, layoutParams);<br>}</pre><p>I have some code that fetches the image, adds the image as a background to my custom view, and adds the text “Code with Lisa” to a bottom corner of the image. I have a callback waiting for my image to load from the server. In my callback, I include the following code.</p><pre>layoutObserver.addOnGlobalLayoutListener(new LayoutListener());</pre><p>Now I am listening for any updates the Android OS makes to my view (i.e. I am listening for Android to set my custom view’s background to the fetched image).</p><p>LayoutListener will be called when the final composition has been drawn. Once it’s been called, we want to make sure to remove the callback so that we are not repeatedly called unintentionally when any future state within the layout changes.</p><p>Now I am ready to save my view as a bitmap and kick off a task to save this image to the user’s gallery. The code from LayoutListener is below.</p><pre>Bitmap bitmap = mySecretCompositionView.getDrawingCache();</pre><pre>SaveImageToGalleryTask saveImage = new saveImageToGalleryAsyncTask(bitmap);</pre><pre>saveImage.execute();</pre><pre>mySecretCompositionView<br>     .getViewTreeObserver()<br>     .removeOnGlobalLayoutListener(this);</pre><p>Hold on though, that’s not all! We have some clean up to do.</p><pre>private void detachFromWindow() {<br>    try {<br>        windowManager.removeView(mySecretCompositionView);<br>    } catch (IllegalArgumentException e) {<br>        Log.d(PhotoManager.getSimpleClassName(), &quot;View not attached to window manager&quot;);<br>    }<br>}</pre><p>Since we’re done with our composition, we need to make sure to remove our custom view from the WindowManager to avoid unintended consequences as the user continues to enjoy our app.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59f87ca04e49" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-lisa/compose-an-image-off-screen-on-android-59f87ca04e49">Compose an image “off screen” on Android</a> was originally published in <a href="https://medium.com/code-with-lisa">Code With Lisa</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Studio 3.2 Canary Review (Part 1) — AndroidX]]></title>
            <link>https://medium.com/code-with-lisa/android-studio-3-2-canary-review-part-1-androidx-8f04d58a2136?source=rss-95f8e32d856b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f04d58a2136</guid>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Lisa Watkins]]></dc:creator>
            <pubDate>Sat, 16 Jun 2018 16:37:02 GMT</pubDate>
            <atom:updated>2018-06-16T16:38:33.597Z</atom:updated>
            <content:encoded><![CDATA[<p>This year at Google I/O, <strong>Android Studio 3.2 Canary</strong> was announced and released for download. Android Studio 3.2 has a variety of exciting features that support other I/O announcements, including <strong>Android Jetpack</strong> and <strong>Android App Bundle</strong>.</p><p>What better way to test these new features than to refactor an app I haven’t touched in nearly a year? Allow me to take you on a journey of refactoring a simple app that uses the New York Times Search API to retrieve news articles. You can find the source code <a href="https://github.com/lisamariewatkins/NewYorkTimesSearch">here</a>.</p><p>The first thing I noticed after opening Android Studio 3.2 Canary was a friendly new feature called “Assistant”. Unfortunately, the assistant is not voice activated like the Google Home Mini I received at I/O, but it is a useful little panel that informs you of any software updates to Android Studio.</p><p>As I mentioned earlier, Android Jetpack was announced at I/O this year. One of the features of Android Jetpack is the <strong>AndroidX</strong> library, the new namespace under which Google has refactored the Android Support library. AndroidX also includes Architecture Components. Google’s reasoning for this shift is that the versioning of the support library has become really confusing (I’d venture to say that most Android developers agree), and this way it can be clear going forward which dependencies to include and how the API’s are divided.</p><p>Migrating from the Support Library namespace to AndroidX is very simple with Android Studio 3.2. Simply select “Migrate to AndroidX…” from the “Refactor” menu. Not kidding, it’s that easy.</p><p>The only issue so far with migrating to AndroidX has been incompatibility with ButterKnife. The generated code from ButterKnife is looking for the old support library namespaces, and not the AndroidX namespace. I saw that this <a href="https://github.com/JakeWharton/butterknife/commit/f0b735144d24592d665eeff90051b6adea2e564a">commit</a> in the ButterKnife project aims to fix this issue, but even after cleaning the project and bumping up to ButterKnife 8.8.1, there still appears to be some bugs. For reasons like this, I don’t recommend refactoring your production code to AndroidX until 3.2 is stable and your other dependencies have had time to catch up.</p><p>Overall I think this feature worked really well, but it would be nice if 3.2 could inform you on mismatched namespaces between the support library and AndroidX for your dependencies.</p><p>Stay tuned for more Android Studio 3.2 Canary reviews, next up I will be exploring the <strong>Slice Provider</strong>, <strong>Navigation Editor</strong>, and more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f04d58a2136" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-lisa/android-studio-3-2-canary-review-part-1-androidx-8f04d58a2136">Android Studio 3.2 Canary Review (Part 1) — AndroidX</a> was originally published in <a href="https://medium.com/code-with-lisa">Code With Lisa</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get results from Android Chooser]]></title>
            <link>https://medium.com/code-with-lisa/get-results-from-android-chooser-9cfc5445a871?source=rss-95f8e32d856b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cfc5445a871</guid>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Lisa Watkins]]></dc:creator>
            <pubDate>Thu, 29 Mar 2018 02:50:13 GMT</pubDate>
            <atom:updated>2018-03-29T02:55:16.031Z</atom:updated>
            <content:encoded><![CDATA[<p>Perhaps you have some sort of content that your users would like to email to their coworker or share with their Instagram friends. Perhaps you’d like to take it a step further, and get some insight into where your users are sharing your app’s content or kick off some background task once the user selects an app.</p><p>As of Lollipop (API Level 22), the <a href="https://developer.android.com/reference/android/content/Intent.html"><em>Intent</em></a> class contains a new #createChooser method that takes an <a href="https://developer.android.com/reference/android/content/IntentSender.html"><em>IntentSender</em></a> parameter.</p><pre><a href="https://developer.android.com/reference/android/content/Intent.html">Intent</a> createChooser (<a href="https://developer.android.com/reference/android/content/Intent.html">Intent</a> target, <a href="https://developer.android.com/reference/java/lang/CharSequence.html">CharSequence</a> title,    <br>                      <a href="https://developer.android.com/reference/android/content/IntentSender.html">IntentSender</a> sender)</pre><p>An <em>IntentSender</em> is simply an abstraction around an <em>Intent</em> with some action you intend to perform with that <em>Intent</em>. In our case, we are using an <em>IntentSender</em> to broadcast that our user has selected an app.</p><p>An <em>IntentSender</em> is created with a <em>PendingIntent</em>. It’s important to note that <strong>you need to create a </strong><a href="https://developer.android.com/reference/android/app/PendingIntent.html"><strong><em>PendingIntent</em></strong></a><strong> to create an <em>IntentSender</em>. </strong>This means that in total, we are creating two <em>Intent</em>s (a “receiver” <em>Intent</em> and a “share” <em>Intent</em>) and one <em>PendingIntent</em>.</p><p>We pass in a custom <em>BroadcastReceiver</em> to our receiver intent’s constructor. The <em>BroadcastReceiver</em>’s #onReceive method acts as a callback for the user selecting an app from the app chooser.</p><p>Lets write our <em>BroadcastReceiver</em> first.</p><pre>public class MyReceiver extends <a href="https://developer.android.com/reference/android/content/BroadcastReceiver.html">BroadcastReceiver</a> {<br><br>    @Override<br>    public void onReceive(<a href="https://developer.android.com/reference/android/content/Context.html">Context</a> context, <a href="https://developer.android.com/reference/android/content/Intent.html">Intent</a> intent) {<br>        super.onReceive(context, intent);<br>        // do something here<br>    }<br>}</pre><p>Make sure to add the following line to your <em>AndroidManifest.xml</em> file. The <em>android:exported=”false” </em>tag simply ensures that apps outside of our application can’t send messages to this <em>BroadcastReceiver</em>.</p><pre>&lt;receiver android:name=&quot;MyReceiver&quot; android:exported=&quot;false&quot;/&gt;</pre><p>We now need to write our receiver <em>Intent</em>, passing in the <em>MyReceiver</em> to it’s constructor.</p><pre>Intent receiver = new Intent(context, MyReceiver.class);</pre><p>Now, we can use our receiver <em>Intent</em> to create a <em>PendingIntent</em>. The receiver <em>Intent</em> is used to create the <em>PendingIntent</em>’s <em>IntentSender</em>. We need this later in our #createChooser method, and this is how we wire up <em>MyReceiver</em>’s #onReceive method to be called once a user makes a selection.</p><pre>PendingIntent pendingIntent = PendingIntent.<em>getBroadcast</em>(context, 0, receiver, PendingIntent.<em>FLAG_UPDATE_CURRENT</em>);</pre><p>And of course, we need to build our share intent. In this example, we are sharing an image.</p><pre><a href="https://developer.android.com/reference/java/lang/String.html">String</a> type = &quot;image/*&quot;;<br><a href="https://developer.android.com/reference/android/content/Intent.html">Intent</a> share = new Intent(Intent.<em>ACTION_SEND</em>);<br>share.setType(type);<br>share.putExtra(Intent.<em>EXTRA_STREAM</em>, awesome_photo_uri);</pre><p>Now, putting it all together:</p><pre>startActivity(Intent.<em>createChooser</em>(share<br>                                , &quot;some_title&quot;<br>                                , pendingIntent.getIntentSender()));</pre><p>And, ta-da! Now your app is listening for the user to make a selection and share your app’s content. You can do something like the line below in your #onReceive method to find out which app the user shared the photo to.</p><pre>String selectedAppPackage = String.valueOf(intent.getExtras().get(<em>EXTRA_CHOSEN_COMPONENT</em>))</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cfc5445a871" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-lisa/get-results-from-android-chooser-9cfc5445a871">Get results from Android Chooser</a> was originally published in <a href="https://medium.com/code-with-lisa">Code With Lisa</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>