<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Mick F</title><description>Notes for myself and fellow programmers, with a focus on iOS, Swift and web frontend development. Since 2009.</description><link>https://www.mickf.net/tech/</link><item><title>DroidCon 2014</title><link>https://www.mickf.net/tech/droidcon-2014/</link><guid isPermaLink="true">https://www.mickf.net/tech/droidcon-2014/</guid><pubDate>Wed, 22 Oct 2014 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;You can watch all the videos on &lt;a href=&quot;https://www.youtube.com/channel/UCkatLlah5weIpN23LqMgdTg&quot;&gt;the Droidcon Paris Youtube
channel&lt;/a&gt; but I especially recommend these 3 talks.&lt;/p&gt;
&lt;h2 id=&quot;scaling-android-development-at-twitter&quot;&gt;&lt;em&gt;Scaling Android Development at Twitter&lt;/em&gt;&lt;/h2&gt;
&lt;p&gt;&lt;img alt=&quot;Scaling Android Development at Twitter&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; inputtedWidth=&quot;1243&quot; width=&quot;1243&quot; height=&quot;708&quot; src=&quot;https://www.mickf.net/_vercel/image?url=build%2Fdroidcon-jan-chong.CPpLNp4m.png&amp;amp;w=1080&amp;amp;q=100&quot;&gt;&lt;/p&gt;
&lt;p&gt;This talk by &lt;a href=&quot;http://en.wikipedia.org/wiki/Software_release_train&quot;&gt;Jan Chong&lt;/a&gt;, engineering manager at Twitter for
Android, was about how Twitter’s mobile team transitioned from a 5-people team
to a 70+ contributors effort. Here are some key points from the talk.&lt;/p&gt;
&lt;p&gt;You can watch it &lt;a href=&quot;http://youtu.be/T5qEnillTHc&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;operations&quot;&gt;Operations&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;In 3 years, Twitter for Android went from a 8 to 12 weeks release schedule to
1 release a week&lt;/li&gt;
&lt;li&gt;The key quality indicator they’re following are crashed : they analyzed that
when a user experienced a crash, his engagement would drop significantly for
the next month (of course, they use &lt;a href=&quot;https://try.crashlytics.com&quot;&gt;Crashlytics&lt;/a&gt;, that they own)&lt;/li&gt;
&lt;li&gt;API released for mobiles need to be supported for a loooooong time&lt;/li&gt;
&lt;li&gt;They baked an API mechanism to support A/B testing within their apps that does
not require republishing&lt;/li&gt;
&lt;li&gt;They also have an interesting feature switch system where they remotely
control a device/manufacturer/OS version matrix to swith features on and off,
again to be able to tune their apps and avoir crashes without the need to
republish&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;tools-and-processes&quot;&gt;Tools and processes&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;They’re using Gradle and Android Studio&lt;/li&gt;
&lt;li&gt;Twitter practice &lt;a href=&quot;http://en.wikipedia.org/wiki/Eating_your_own_dog_food&quot;&gt;dogfooding&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;They switched from &lt;a href=&quot;https://code.google.com/p/robotium/&quot;&gt;Robotium&lt;/a&gt; to &lt;a href=&quot;https://code.google.com/p/android-test-kit/wiki/Espresso&quot;&gt;Espresso&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;They also use &lt;a href=&quot;https://developer.android.com/training/testing/ui-automator&quot;&gt;uiautomator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;They use a &lt;a href=&quot;http://en.wikipedia.org/wiki/Software_release_train&quot;&gt;release train&lt;/a&gt; schedule to run their and
transitioned from a single 4-week train to two concurrent 2-weeks trains to
reduce the gap between deadlines&lt;/li&gt;
&lt;li&gt;They also use a “+1/+2” code review system&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;how-open-source-powers-facebook-on-android-by-simon-stewart&quot;&gt;&lt;em&gt;How Open Source Powers Facebook on Android&lt;/em&gt;, by Simon Stewart&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://youtu.be/MT6bU9ofJDE&quot;&gt;📺&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;petit-design-pour-grande-humanité-by-geoffrey-dome&quot;&gt;&lt;em&gt;Petit Design pour Grande Humanité&lt;/em&gt;, by Geoffrey Dome&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://youtu.be/mwF4qk9OMe8&quot;&gt;📺&lt;/a&gt;&lt;/p&gt;
</content:encoded><category>Conference</category><category>Android</category></item><item><title>Service to Activity Communication With The Android SDK</title><link>https://www.mickf.net/tech/android-service-activity-communication/</link><guid isPermaLink="true">https://www.mickf.net/tech/android-service-activity-communication/</guid><pubDate>Tue, 28 Jan 2014 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I’m an experienced iOS developer but still consider myself a noob regarding
Android development. Never mind, I still want to share my latest experiment with
the Android SDK: how to run a long operation in the background while still
updating the UI regularly?&lt;/p&gt;
&lt;h2 id=&quot;where-asynctask-wont-do-the-job&quot;&gt;Where AsyncTask won’t do the job…&lt;/h2&gt;
&lt;p&gt;The Android SDK provides a convenient object to perform background operations
that will need to provide a UI feedback: &lt;a href=&quot;https://developer.android.com/reference/android/os/AsyncTask.html&quot; title=&quot;AsyncTask Class API Reference&quot;&gt;&lt;code&gt;AsyncTask&lt;/code&gt;&lt;/a&gt;. But as
&lt;a href=&quot;https://developer.android.com/reference/android/os/AsyncTask.html&quot; title=&quot;AsyncTask Class API Reference&quot;&gt;Android’s documentation&lt;/a&gt; says:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;AsyncTasks should ideally be used for short operations (a few seconds at the
most.)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The question then arises: what should we use when a longer background operation
is needed?&lt;/p&gt;
&lt;h2 id=&quot;well-guess-what-it-depends&quot;&gt;Well, guess what? It depends…&lt;/h2&gt;
&lt;p&gt;Searching for an answer to this question on services like StackOverflow ends up
being more confusing than helpful. &lt;a href=&quot;https://stackoverflow.com/search?q=android+ui+communication+background&quot; title=&quot;Search for &amp;#x27;Android UI Communication Background&amp;#x27; on StackOverflow&quot;&gt;Many questions&lt;/a&gt; are asked in
this area but no clear answer appears. But depending on the specific aspects of
each question, many keywords appear to help getting our quest further:
&lt;code&gt;Services&lt;/code&gt;, &lt;code&gt;Handlers&lt;/code&gt;, etc.&lt;/p&gt;
&lt;h2 id=&quot;lets-give-services-a-try&quot;&gt;Let’s give Services a try&lt;/h2&gt;
&lt;p&gt;Ideally, I wanted to find something similar to the &lt;a href=&quot;https://nshipster.com/key-value-observing/&quot;&gt;KVO&lt;/a&gt; mechanism in iOS.&lt;/p&gt;
&lt;p&gt;I decided to give &lt;code&gt;Services&lt;/code&gt; a try and developed a &lt;a href=&quot;https://en.wikipedia.org/wiki/Proof_of_concept&quot; title=&quot;Proof of Concept&quot;&gt;POC&lt;/a&gt; you can find on
&lt;a href=&quot;https://github.com/dirtyhenry/bootstragram-android&quot; title=&quot;My bootstragram-android repository on GitHub&quot;&gt;my bootstragram-android repository on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The main reason why I picked &lt;code&gt;Services&lt;/code&gt; over other solutions is that I wanted to
be able to share &lt;em&gt;any kind of objects&lt;/em&gt;, not only &lt;code&gt;Serializable&lt;/code&gt; and &lt;code&gt;Parcelable&lt;/code&gt;
ones. This constraint eliminated a solution based on a
&lt;a href=&quot;https://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager.html&quot; title=&quot;LocalBroadcastManager Class API Reference&quot;&gt;&lt;code&gt;LocalBroadcastManager&lt;/code&gt;&lt;/a&gt; as from my understanding,
objects that can be passed with the &lt;code&gt;Intent&lt;/code&gt; (ie &lt;code&gt;Extra&lt;/code&gt;) have to be
&lt;code&gt;Serializable&lt;/code&gt; or &lt;code&gt;Parcelable&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;My objectives for this POC were:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create a background operation that will live as long as my app, no less.&lt;/li&gt;
&lt;li&gt;This operation must run continously and must update some kind of state at a
relatively high-frequency.&lt;/li&gt;
&lt;li&gt;The user must be able to get a UI representation of that state without being
blocked on one activiy in particular.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Some notes about it went follow.&lt;/p&gt;
&lt;h3 id=&quot;the-poc-story&quot;&gt;The POC Story&lt;/h3&gt;
&lt;p&gt;The pitch for the POC is as silly as can be. The app will generate in the
background a new hex-string every 2 seconds. It will have to be displayed in a
screen with a new color. Wow! I’m sure this app would be a hit on the Google
Play Store!&lt;/p&gt;
&lt;h3 id=&quot;create-a-service&quot;&gt;Create a Service&lt;/h3&gt;
&lt;p&gt;When you create a &lt;code&gt;Service&lt;/code&gt;, you need to declare it in your app manifest. I made
mine private to my app but it’s not required.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; style=&quot;background-color:#24292e;color:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;xml&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#85E89D&quot;&gt;application&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; ...&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;  ....&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#85E89D&quot;&gt;service&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt; android:name&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;&quot;.services.RandomEventsService&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;           android:exported&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;&quot;false&quot;&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; &amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;  &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#85E89D&quot;&gt;service&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;  ....&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#85E89D&quot;&gt;application&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The service itself is a subclass of &lt;a href=&quot;https://developer.android.com/reference/android/app/IntentService.html&quot; title=&quot;IntentService Class API Reference&quot;&gt;&lt;code&gt;IntentService&lt;/code&gt;&lt;/a&gt; (which
provides a convenient &lt;code&gt;onHandleIntent&lt;/code&gt; method to override) doing very simple
things:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; style=&quot;background-color:#24292e;color:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;java&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;protected&lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt; void&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt; onHandleIntent&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;(Intent intent) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;  while&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;    final&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; RandomSingleton singleton &lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; RandomSingleton.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;getInstance&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;    singleton.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;increment&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;    long&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; endTime &lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; System.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;currentTimeMillis&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; 1000&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;    while&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; (System.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;currentTimeMillis&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; endTime) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;      synchronized&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;        try&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;          wait&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;(endTime &lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; System.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;currentTimeMillis&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;        } &lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt;catch&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; (Exception &lt;/span&gt;&lt;span style=&quot;color:#FFAB70&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;          Log.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;(TAG, &lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;&quot;Couldn&apos;t sleep in peace&quot;&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;, e);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;      }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;      singleton.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;increment&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The service just runs continously and wakes up every 2 seconds to update the
&lt;code&gt;RandomSingleton&lt;/code&gt; singleton object via the &lt;code&gt;increment()&lt;/code&gt; method: objectives 1
and 2 are achieved.&lt;/p&gt;
&lt;p&gt;Here is &lt;a href=&quot;https://github.com/dirtyhenry/bootstragram-android/blob/master/src/com/bootstragram/demo/services/RandomEventsService.java&quot; title=&quot;My RandomEventsService source code&quot;&gt;the full source code&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The service is started via a button in an activity:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; style=&quot;background-color:#24292e;color:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;java&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt; void&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt; onClick&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;(View v) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;  Intent intent &lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt; Intent&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;(ServiceFeedbackActivity.this, RandomEventsService.class);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;  startService&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;(intent);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;ui-representation-and-notifications&quot;&gt;UI Representation and Notifications&lt;/h3&gt;
&lt;p&gt;We still have objective 3 to achieve. To do so:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;I made my &lt;code&gt;RandomSingleton&lt;/code&gt; a subclass of
&lt;a href=&quot;https://developer.android.com/reference/android/database/ContentObservable.html&quot; title=&quot;ContentObservable Class API Reference&quot;&gt;&lt;code&gt;ContentObservable&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;I created an activity using a subclass of
&lt;a href=&quot;https://developer.android.com/reference/android/database/ContentObserver.html&quot; title=&quot;ContentObserver Class API Reference&quot;&gt;&lt;code&gt;ContentObserver&lt;/code&gt;&lt;/a&gt;, observing &lt;code&gt;RandomSingleton&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Then I made &lt;code&gt;RandomSingleton&lt;/code&gt; call &lt;code&gt;dispatchChange(...)&lt;/code&gt; at the end of the
&lt;code&gt;increment()&lt;/code&gt; method&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;And that’s it.&lt;/p&gt;
&lt;h3 id=&quot;the-result&quot;&gt;The Result&lt;/h3&gt;
&lt;p&gt;&lt;img alt=&quot;The app updates the UI every 2s accordingly to the new singleton state&quot; title=&quot;The app updates the UI every 2s accordingly to the new singleton state&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; inputtedWidth=&quot;463&quot; width=&quot;463&quot; height=&quot;245&quot; src=&quot;https://www.mickf.net/_vercel/image?url=build%2Fandroid-services-to-activity-communication.CHJ7XyqO.gif&amp;amp;w=512&amp;amp;q=100&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;After a frustrating research that had made me more confused than confident about
my problem, I found out that the actual implementation was pretty
straightforward and easier to implement than I expected.&lt;/p&gt;
&lt;p&gt;Nevertheless, I’m still curious of feedbacks you might have about this code and
I invite you to get in touch via &lt;a href=&quot;https://github.com/dirtyhenry/tech-articles/issues&quot; title=&quot;Issues&quot;&gt;GitHub&lt;/a&gt; if you want to engage a
discussion about this page (in particular if you know a better way to do a
Service to UI communication).&lt;/p&gt;
</content:encoded><category>Android</category></item></channel></rss>