<?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 Grzegorz Podbielski on Medium]]></title>
        <description><![CDATA[Stories by Grzegorz Podbielski on Medium]]></description>
        <link>https://medium.com/@podbielski.grzegorz?source=rss-993388f84e78------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6oI3azoDvehQIiy79YaGvg.jpeg</url>
            <title>Stories by Grzegorz Podbielski on Medium</title>
            <link>https://medium.com/@podbielski.grzegorz?source=rss-993388f84e78------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 12:56:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@podbielski.grzegorz/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[7 common performance issues that can occur in your app]]></title>
            <link>https://medium.com/indoorway-blog/7-common-performance-issues-that-can-occur-in-your-app-b8120e1c3da3?source=rss-993388f84e78------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8120e1c3da3</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[rxjava]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[english]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Grzegorz Podbielski]]></dc:creator>
            <pubDate>Fri, 21 Sep 2018 08:24:07 GMT</pubDate>
            <atom:updated>2019-03-13T18:09:45.616Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OrqlrIThXF20tv-zExUu1Q.png" /><figcaption>Illustration by <a href="https://www.behance.net/mieleszko">Justyna Mieleszko</a></figcaption></figure><p>They can be seen right at first sight, after some time or on specific kind of devices. In the post below, I will share my thoughts on the most common problems with app performance, ways those issues can undermine your work and the easiest way to solve them.</p><h4><strong>1. Memory leaks when subscriptions in RxJava are not cleared</strong></h4><p>They occur when an object in memory is not deleted, even if it is no longer needed. In RxJava, a popular library in Android ecosystem, it often happens when users don’t clear their subscriptions correctly.<br>When subscribing to the Observable an anonymous class is created, which always keep reference to their calling class. In result, if you don’t clear subscription, an anonymous class will keep outer class instance and all variables that you used inside them.<br>Fortunately, there is a simple solution to avoid this problem. All you need to do is <strong>create CompositeSubscription</strong> and then clear it after it is no longer needed.</p><h4><strong>2. Not unsubscribing from sensor listeners</strong></h4><p>When you are registering a new sensor listener, you need to pass the Context as a service listener. If you forget to unregister it, it will keep Activity instance even after it’s no longer necessary for creating a memory leak.<br>One of the best ways to help you notice memory leaks is <strong>using the LeakCanary library</strong>. It will notify you anytime it notices your memory is not released when it should be.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl3q2MDnkLri1t7i5a%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fl3q2MDnkLri1t7i5a&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fl3q2MDnkLri1t7i5a%2Fgiphy.gif%3Fcid%3D790b761168ecb1fdf3b2ff6ce63ed8b976d486fdbb5c43d1%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad61b918a1f42935ef1589909ab4bab4/href">https://medium.com/media/ad61b918a1f42935ef1589909ab4bab4/href</a></iframe><h4><strong>3. Adding inappropriate resources</strong></h4><p>In general, I recommend using vector drawables wherever possible. It has, theoretically, a slightly higher performance impact, but it reduces overall apk size and leaves image scaling to the system. Sometimes with performance-sensitive jobs you will need bitmaps. When using png drawables you should always use the appropriate resource dimension. You should remember then about no-dpi dimension. These resources won’t be scaled at all.<br>At Indoorway we had a problem with a map background once. Firstly, we put it in the folder with scaled resource and then we tried to scale it according to the user’s needs. In result, the map was scaled twice and it shuttered.</p><h4><strong>4. Keeping too big images</strong></h4><p>Beginners often keep too big images. Usually you see a list of thumbnails which enlarge to full view after clicking. At the beginning people often download images, put them into the list view, then let them resize. That way we are downloading a full sized image and keep it in memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*f-JKsO5bZr_M79vtNFK6-Q.jpeg" /></figure><p>A better approach is to <strong>use a library like Picasso</strong> and scale images on flight. That way you store only a thumbnail. It loads to full image after a click.<br>Here you’ll find a Google’s video that should help you with more complicated problems:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FHY9aaXHx8yA%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DHY9aaXHx8yA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FHY9aaXHx8yA%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/42385c40d8da0c340b72125241b408a6/href">https://medium.com/media/42385c40d8da0c340b72125241b408a6/href</a></iframe><h4><strong>5. Performing resource-exhausting tasks too often</strong></h4><p>Every app profiling you should start by looking at components that take time to process. We are often doing monotonous computing heavy work in background when we could just cache the result for future use, or we repeatedly load something that could be stored in memory. <br>The best tool to deal with such problem is <strong>Android Profiler</strong>. Take a look at the methods that are the computational heaviest and then start your work from there.</p><p>In my next article I’ll show an example of how to find these problematic parts in your code with Android Profiler.</p><h4><strong>6. Testing always on high-end device</strong></h4><p>Many issues, not only performance-related, can be noticed only on slower devices. For example, a process, that is fast on Galaxy S9 can be really bothering to user with the old Motorola. Of course, you should always remember to test your app on devices, that your users will own in the future, just don’t forget that many people worldwide do not have the latest models of phones and you should keep them happy as well.</p><h4><strong>7. Performance is relevant</strong></h4><p>The last advice is to keep in mind that performance is relevant to the user. Make sure your app is responsive and gives proper feedback. People like to know what is going on. They prefer to be informed about the level of progression (you can show it with a simple progress bar) rather than be surprised after a while with the app freeze or worse — the ANR dialog. Even if the app needs time to complete some processes in background, keep your users informed and they will be more forgiving.</p><p>As you can see, there are many performance-related aspects that you should keep in mind while working on the app. At first, those issues can be unnoticable but after some time they accumulate and can be problematic to the users. Hopefully, after reading this article you already become aware of the most common problems. In the next post I’ll show you how to detect some more sneaky leaks with memory profiler.</p><figure><a href="https://www.indoorway.com/"><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*bRmYAr8LV10uXDGivvzbCA.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8120e1c3da3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/indoorway-blog/7-common-performance-issues-that-can-occur-in-your-app-b8120e1c3da3">7 common performance issues that can occur in your app</a> was originally published in <a href="https://medium.com/indoorway-blog">Indoorway Blog | Actual data about your manufacturing processes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Over and done with unexpected multithreading errors. Our take on Redux]]></title>
            <link>https://medium.com/indoorway-blog/over-and-done-with-unexpected-multithreading-errors-our-take-on-redux-13884431cb4b?source=rss-993388f84e78------2</link>
            <guid isPermaLink="false">https://medium.com/p/13884431cb4b</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[english]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Grzegorz Podbielski]]></dc:creator>
            <pubDate>Fri, 06 Apr 2018 13:12:29 GMT</pubDate>
            <atom:updated>2019-03-13T18:32:21.241Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*xt7uiYZHIguazIB7H_3cRQ.png" /><figcaption>Illustration by <a href="https://dribbble.com/magdalenatomczyk">Magdalena Tomczyk</a></figcaption></figure><p><strong>At Indoorway we develop mobile apps to smarten up brick-and-mortar buildings. We create many of them and deadlines are usually tight. Thus, as an Android developer, I was looking for a reliable architecture that fits mobile devices well. That’s how I found Redux, and I’ll absolutely stick with it.</strong></p><p>Redux has been created by <a href="https://twitter.com/dan_abramov">Dan Abramov</a>, primarily to design single page web applications. The aim of the framework is to make managing app states easy and predictable. Asynchronous tasks (needed so much in Android world) and mutability can lead to disaster: race conditions, unpredictable state changes, you name it. Redux introduces 3 principles that help us with taming these problems.</p><h4><strong>Why do we use Redux on Android?</strong></h4><p>Android apps rely heavily on background jobs and multitasking, which makes us, developers struggle with handling configuration changes, app restarting, going to background, etc. every single day. It often leads to unpredictable app behaviour or nasty bugs.</p><p>Redux helps us with managing these concerns by defining a clear state, in which the app is at the moment. We can easily come back to the previous state or even transfer a state between platforms.</p><p><strong>Redux has 3 principles that allow us achieve this:</strong></p><ul><li><strong>Single source of truth </strong>— all state data is kept in a single store. It is useful as you can easily debug and pass data between screens. It’s also easy to serialize the whole app state to recreate it later.</li><li><strong>Read-only state </strong>— the only way to change the app state is to emit an event. Thanks to this and immutabile state you always know in what state the app is and concurrent actions won’t interfere with one another.</li><li><strong>Changes are made with pure functions</strong> — reducers should be pure functions that only take the previous state and action to return the next state. Reducer should be as simple as possible and just return a new state without meddling with previous one.</li></ul><h4><strong>How do we do it?</strong></h4><p>OK, let’s set up the basis for our architecture. At Indoorway we don’t use any architecture-specific library. We implemented almost everything ourselves, using a few external libraries of our choice.</p><p>We use RxJava2, RxRelay and RxLifecycle to avoid managing Observables lifetime explicitly.</p><p>I will describe the most crucial parts of the app. If you want to see the full sample project you can check it out at: <a href="https://github.com/indoorway/ReduxAndroidSampleApp">https://github.com/indoorway/ReduxAndroidSampleApp</a></p><h4><strong>Three basic concepts</strong></h4><p>In Redux there are 3 basic concepts:</p><p><strong>action</strong> — it is an event that triggers state change. We declare it as a common interface, which will be then implemented by feature-specific events.</p><pre>interface AppEvent</pre><p>In our sample app we have the main feature, which has one action triggered on Activity creation. Actions are objects or data classes, when we need to pass any data.</p><pre>sealed class MainEvent : AppEvent {<br>    object OnCreate : MainEvent()<br>}</pre><p><strong>state</strong> — describes state of the app. It should be immutable to allow seamless multi thread state change.</p><p>Data class, which is the base for other, more specific states, looks like that:</p><pre>data class AppState(val main: MainState)</pre><p>The state usually reflects the one of our screen. We include there everything screen-specific, like actual data that should be displayed. Then we can easily manage these states in our model.</p><pre>data class MainState(<br>        val githubData: GithubResponse?,<br>        val showLoader: Boolean,<br>        val showError: Boolean)</pre><p><strong>reducer</strong> — it is a simple function, which — for a given event and previous state — returns a new state without meddling with previous one. In our case base function looks like this:</p><pre>typealias GeneralSubReducer&lt;UiState&gt; = (eventsRelay: Relay&lt;AppEvent&gt;, events: Observable&lt;AppEvent&gt;, states: Observable&lt;UiState&gt;) -&gt; Observable&lt;UiState&gt;</pre><h4><strong>Core classes</strong></h4><p>In our Redux implementation we maintain Global state, so we can use it in every part of the app. We store it in GlobalModel class.</p><p>First, we have base interface GeneralModel, which stores all events and feature-specific states:</p><pre>abstract class GeneralModel&lt;UiEvent, UiState&gt;(defaultState: UiState){<br>    val events = PublishRelay.create&lt;UiEvent&gt;()<br>    val states = BehaviorRelay.createDefault&lt;UiState&gt;(defaultState)<br>}</pre><p>Second, basing on this we implement GlobalModel:</p><pre>class GlobalModel(initialState: AppState,<br>                  private val mainReducer: GeneralSubReducer&lt;MainState&gt;<br>) : GeneralModel&lt;AppEvent, AppState&gt;(initialState) {<br><br>    val mainState: Observable&lt;MainState&gt; = states.<em>mapNotNull </em><strong>{ it</strong>.main <strong>}<br><br>    </strong>init {<br>        Observable.merge(<em>listOf</em>(<br>                main()<br>        )).subscribe(states)<br>    }<br><br>    private fun main() =<br>            mainReducer(events, events, mainState)<br>                    .<em>onLatestFrom</em>(states) <strong>{ </strong>copy(main = <strong>it</strong>) <strong>}<br><br>    </strong>companion object {<br><br>        fun initialAppState(): AppState {<br>            return AppState(main = MainModel.initialState())<br>        }<br>    }<br>}</pre><p>Here we have our main state, which is a part of global state:</p><pre><br>    val mainState: Observable&lt;MainState&gt; = states.<em>mapNotNull </em><strong>{ it</strong>.main <strong>}<br></strong></pre><p>Then we implement our main reducer,</p><pre>private fun main() =<br>        mainReducer(events, events, mainState)<br>                .<em>onLatestFrom</em>(states) <strong>{ </strong>copy(main = <strong>it</strong>) <strong>}</strong></pre><p>which we add to reducers list.</p><pre>init {<br>    Observable.merge(<em>listOf</em>(<br>            main()<br>    )).subscribe(states)<br>}</pre><p>In companion object we have the initial state of our AppState. We’ll add similar initializer in feature states.</p><p>Before we implement feature-specific models, let’s declare its super class. It will contain process method, which will allow us pass events to feature specific methods.</p><pre>abstract class GeneralSubModel&lt;UiState&gt;(val states: Observable&lt;UiState&gt;) {<br>    abstract fun process(events: Observable&lt;AppEvent&gt;): Observable&lt;UiState&gt;<br>}</pre><p>Here we have our generic GeneralSubModel, which has process method in which it is merging it all.</p><p>Finally, we can get to our MainModel. Here we override the process method mentioned before,</p><pre>override fun process(events: Observable&lt;AppEvent&gt;): Observable&lt;MainState&gt; {<br>    return Observable.merge(<em>listOf</em>(callApiOnCreate(events)))<br>}</pre><p>which passes events to our business logic methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*rSOvPUqLdmFr1f063C7Z7A.png" /></figure><h4><strong>Network jobs</strong></h4><pre>private fun callApiOnCreate(events: Observable&lt;AppEvent&gt;): Observable&lt;MainState&gt; {<br>    return events.ofType(MainEvent.OnCreate::class.<em>java</em>)<br>            .<em>withLatestFrom</em>(states, <strong>{ </strong>event, state <strong>-&gt; </strong>event <em>to </em>state <strong>}</strong>)<br>            .filter <strong>{ </strong>(_, state) <strong>-&gt; </strong>state.githubData == null <strong>}<br>            </strong>.flatMap <strong>{ </strong>(event, state) <strong>-&gt;<br>                </strong>api.getUserData(&quot;octokit&quot;)<br>                        .subscribeOn(ioScheduler)<br>                        .toObservable()<br>                        .<em>onLatestFrom</em>(states) <strong>{<br>                            </strong>copy(githubData = <strong>it</strong>.<em>first</em>(), showLoader = false, showError = false)<br>                        <strong>}<br>                        </strong>.observeOn(uiScheduler)<br>                        .startWith(state.copy(showLoader = true, showError = false))<br>                        .doOnError <strong>{ </strong>Log.e(<em>javaClass</em>.<em>simpleName</em>, <strong>it</strong>.message, <strong>it</strong>) <strong>}<br>                        </strong>.onErrorReturn <strong>{ </strong>states.blockingFirst().copy(showError = true, showLoader = false) <strong>}<br>            }<br></strong>}</pre><p>OK, there’s a lot to process.</p><p>Here we have network request to get github data.</p><p>First we filter our events looking for MainEvent.OnCreate</p><pre>return events.ofType(MainEvent.OnCreate::class.<em>java</em>)</pre><p>Then we pair event with latest state</p><pre>.withLatestFrom(states, <strong>{ </strong>event, state <strong>-&gt; </strong>event <em>to </em>state <strong>}</strong>)</pre><p>and we filter out cases when github data isn’t null so we won’t download it twice.</p><pre>.filter <strong>{ </strong>(_, state) <strong>-&gt; </strong>state.githubData == null <strong>}</strong></pre><p>In the next lines we send retrofit data request using ioScheduler.</p><pre>api.getUserData(&quot;octokit&quot;)<br>        .subscribeOn(ioScheduler)<br>        .toObservable()</pre><p>Then we take latest state and then we copy it with new data. The copy is important part because to ensure multithread safety we set states to be immutable.</p><pre>.<em>onLatestFrom</em>(states) <strong>{<br>    </strong>copy(githubData = <strong>it</strong>.<em>first</em>(), showLoader = false, showError = false)<br><strong>}</strong></pre><p>After a successful request we should have the state with latest data and our subscription in MainActivity should update UI accordingly.</p><p>Going further, we are defining in which state our app should be just after request start. In our example we set to show loader and don’t show error.</p><pre>.startWith(state.copy(showLoader = true, showError = false))</pre><p>And finally, we handle error case in turn logging error and then updating our state accordingly.</p><pre>.doOnError <strong>{ </strong>Log.e(<em>javaClass</em>.<em>simpleName</em>, <strong>it</strong>.message, <strong>it</strong>) <strong>}<br></strong>.onErrorReturn <strong>{ </strong>states.blockingFirst().copy(showError = true, showLoader = false) <strong>}</strong></pre><p>All we have to do now is implementing our Activity, which should override RxAppCompatActivity, to help us manage lifecycle of Observables.</p><h4><strong>Initializing the model</strong></h4><pre>private fun initModel() {<br>    <em>bind</em>(uiEvents(), <strong>{ </strong>GlobalModelModuleImpl.globalModel.mainState <strong>}</strong>, this::handleStates)}</pre><p>Firstly, we’re attaching ui events bus. It’s our addition to Redux architecture we were lacking. This way we can send custom events from ui to model. We can handle e.g. custom backpress his way.</p><p>Secondly, we point at the part of the app state that we want to use. In our example it is the main state.</p><p>Lastly, we observe main events bus, where we observe state changes:</p><pre>private fun handleStates(states: Observable&lt;MainState&gt;) {<br>    states.publish().<em>apply </em><strong>{<br>        </strong><em>showGithubData</em>()<br>        <em>showNetworkError</em>()<br>        <em>hideNetworkError</em>()<br>    <strong>}</strong>.connect()<br>}</pre><p>Subscription to state change looks like this:</p><pre>private fun Observable&lt;MainState&gt;.showGithubData() {<br>    <em>mapNotNull </em><strong>{ it</strong>.githubData <strong>}<br>            </strong>.distinctUntilChanged()<br>            .subscribe <strong>{ </strong>updateGithubData(<strong>it</strong>) <strong>}<br></strong>}</pre><p>Here we subscribe to githubData changes. If it is not null, we check if data changed since the last fetch. If it did, then we are updating our ui.</p><p>Finally, we send event MainEvent.OnCreate at the start of our Activity, which then is retrieved in our MainModel.</p><pre>private fun uiEvents(): Observable&lt;AppEvent&gt; =<br>        Observable.merge(<em>listOf</em>(<br>                additionalEvents,<br>                Observable.just(MainEvent.OnCreate)<br>        ))</pre><p>We have finally gone through all the code allowing us to make basic Redux application. The solution is easily modifiable. For example, in our project we have custom flavours and di of our own, which we will describe in one of our future articles.<br>Although our blueprint isn’t pure Redux, we are quite pleased with the results and positive that we will implement this architecture in our future apps.</p><h4><strong>Learning by doing</strong></h4><p>The best way to comprehend a new topic is to try it yourself. So go on and create your sample app allowing seamless.</p><figure><a href="https://www.indoorway.com/"><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*QO9xdueFo5qpaiGGfdbzmg.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13884431cb4b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/indoorway-blog/over-and-done-with-unexpected-multithreading-errors-our-take-on-redux-13884431cb4b">Over and done with unexpected multithreading errors. Our take on Redux</a> was originally published in <a href="https://medium.com/indoorway-blog">Indoorway Blog | Actual data about your manufacturing processes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>