<?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 Boonya Kitpitak on Medium]]></title>
        <description><![CDATA[Stories by Boonya Kitpitak on Medium]]></description>
        <link>https://medium.com/@boonya-kitpitak?source=rss-c6b1e8a86f0e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*OzzEJBsp80rkvaJK.</url>
            <title>Stories by Boonya Kitpitak on Medium</title>
            <link>https://medium.com/@boonya-kitpitak?source=rss-c6b1e8a86f0e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 22:29:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@boonya-kitpitak/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[5 Steps to Earn Your First Dollar from Your Mobile App (Built with Flutter)]]></title>
            <link>https://levelup.gitconnected.com/5-steps-to-earn-your-first-dollar-from-your-mobile-app-built-with-flutter-2702ad7ee16b?source=rss-c6b1e8a86f0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2702ad7ee16b</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Boonya Kitpitak]]></dc:creator>
            <pubDate>Tue, 04 Feb 2025 16:08:29 GMT</pubDate>
            <atom:updated>2025-02-04T16:08:29.137Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yMyFhnuu75eKnPDfaGOA8w.png" /></figure><p>Last year, people spent <strong>$43 billion</strong> on apps and in-app purchases through <strong>Google Play</strong> and <strong>$84.3 billion</strong> on the <strong>Apple App Store</strong>. The goal of this article is to help you realize your potential as a mobile developer — especially if you’re using <strong>Flutter</strong> — to tap into that thriving market. In today’s world, with tools like <strong>AI</strong>, <strong>ChatGPT</strong>, <strong>DeepSeek</strong>, and <strong>GitHub Copilot</strong>, individuals have more power than ever to create impactful apps and generate real revenue.</p><h4><strong>Who Is This Article For?</strong></h4><ul><li><strong>Developers new to Flutter:</strong> If you’ve just started learning Flutter and want to create a mobile app that goes beyond a simple sample project to make a real impact.</li><li><strong>Developers with existing apps:</strong> If you already have a mobile app but aren’t sure how to monetize it effectively, this article is for you.</li></ul><h4><strong>My Journey as a Mobile Developer</strong></h4><p>When I started my career as a mobile developer, knowing how to make money from an app wasn’t obvious. As a beginner, you often work on a small part of the development process. Most of the time, you’re given tickets in tools like <strong>Jira</strong>, <strong>Monday</strong>, or <strong>ClickUp</strong> (take your pick), with requirements and designs already prepared for you. However, when you aim to make money from your own app, you need to see the entire picture. It’s no longer just about completing a ticket with polished requirements. You must clearly understand who you’re coding for — not a client, product owner, or project manager, but the <strong>actual users</strong> of your app.</p><h4><strong>Who Am I to Talk About This?</strong></h4><p>Hi, my name is <strong>Ben</strong>. I’m a mobile developer and entrepreneur. Over the past decade, I’ve dedicated my life to mobile app development, starting with <strong>Android</strong> and eventually adding <strong>Flutter </strong>into my arsenal. In the last two years, I’ve been on an entrepreneurial journey, working to make a living from the mobile apps I’ve created. If you’re curious about the kind of apps I develop, check them out here.</p><ul><li><a href="https://ertigo.onelink.me/1dLk/27i1rlav">ERTIGO: Stretch, Less Pain</a></li><li><a href="https://onelink.to/4uhc9q">AI Posture Exercise: NeckFit</a></li></ul><h3>5 Steps to Earn Your First Dollar from Your Flutter App</h3><p>I’ve outlined <strong>five key steps</strong> to help you start making your first dollar from your own app. In this article, we’ll focus on the overall concepts to give you a solid foundation. The implementation details will be covered in future articles, so stay tuned!</p><h3>1. Identify the Problem and Target Audience</h3><p>Don’t start with what you <em>want</em> to make; start with the <strong>problem</strong> you want to solve. It would be disheartening to invest time and effort into building a generic weather app, to-do list, or something else you have no real interest in. Instead, spend a few days researching problems that matter to you. <strong>Avoid jumping straight into coding — if you start with a solution, you’ll miss understanding the real needs of your users.</strong></p><p>Take the time to write a clear and <strong>specific problem statement</strong>. Be as detailed as possible. This will guide you in creating an app that resonates with your target audience. Let’s look at an example to illustrate this concept.</p><h4>Solution-First Thinking vs. Problem-First Thinking</h4><p><strong>If you focus on the solution first:</strong><br><em>“I want to make a focus timer app using Bloc, Riverpod, or Provider pattern.”</em></p><p><strong>If you focus on the problem first:</strong><br><em>“I often struggle to stay focused at work due to constant distractions from Facebook, TikTok, Instagram, and other notifications flooding my phone.”</em></p><p>See the difference between these two approaches:</p><ul><li><strong>Solution-first:</strong> <em>“I will make a focus timer app.”</em></li><li><strong>Problem-first:</strong> <em>“I have trouble focusing on my work due to phone distractions, and I want to solve that problem.”</em></li></ul><p>By starting with the problem, you’ll gain a clearer understanding of your requirements. For instance, the solution might turn out to be an <strong>app blocker</strong> that prevents access to social media during certain hours or a <strong>focus timer</strong> that disables notifications and blocks social media apps while the timer is running. This approach ensures that your app is built to directly address the user’s core problem, making it more effective and valuable.</p><h4>Write Down Your Problem Statement and Audience Before Moving Forward</h4><ol><li><strong>What specific problem am I trying to solve?</strong></li></ol><ul><li><strong>Uber</strong>: People face difficulty finding reliable, safe, and convenient transportation at any time, while drivers have limited access to passengers and earnings.</li><li><strong>Slack: </strong>Teams face communication breakdowns and inefficiencies due to email overload and fragmented tools for real-time collaboration.</li><li><strong>Duolingo: </strong>People want to learn new languages but often lack time, resources, and engaging, structured methods to stay motivated and consistent.</li><li><strong>Yours</strong>? …</li></ul><p>2. <strong>Who Has This Problem?</strong></p><ul><li><strong>Uber: </strong>People who rely on taxis and public transportation for commuting, Drivers seeking better earnings and more passengers.</li><li><strong>Slack: </strong>Corporate teams struggling to collaborate in real-time, Remote and hybrid teams relying heavily on digital communication</li><li><strong>Duolingo: </strong>Individuals who want to learn a new language but lack the time to attend formal classes. Students, travelers, and professionals looking to enhance their language skills.</li><li><strong>Yours</strong>? …</li></ul><h4>Let Your Problem Statement Be Your North Star</h4><p>The problem statement and audience you define at this step will act as your <strong>north star</strong> throughout the development process.</p><ul><li>When you face questions like, <strong><em>“Which feature should be prioritized?”</em></strong> you can refer back to your problem statement. Focus on the feature that will have the <strong>most impact</strong> on solving the problem for your target audience.</li><li>Similarly, when promoting your app, you’ll have a clearer idea of where to focus your efforts. Instead of wasting time and resources on broad marketing, you can target <strong>specific channels</strong> where your audience is most active.</li></ul><p>You are an investor in your app. You invest several hundred hours or even more to create it. So, it&#39;s worth spending a few days doing some research to answer these questions. I know it&#39;s tempting to just start coding, but trust me—having a clear problem and user focus will be your north star and save you a lot of time.</p><h3>2. Check Out Similar Apps</h3><p>Now that you’ve defined your problem statement, it’s time to explore existing solutions for that problem. In today’s world, there’s almost no chance that you’re the first person trying to solve it. There are likely others who have already developed solutions.</p><p>Our goal isn’t to reinvent the wheel but to create something that offers <strong>at least one unique improvement</strong> over existing apps. As <strong>Y Combinator</strong> (the VC firm that invested in companies like Airbnb and Stripe) advises:</p><ul><li><strong>Find a big problem.</strong></li><li><strong>See what people are doing to solve it.</strong></li><li><strong>Create something significantly better.</strong></li></ul><p>You can apply this principle to your indie app development journey as well. Focus on making improvements — no matter how small — that add real value to your users.</p><h4><strong>Simple Steps to Research Existing Apps</strong></h4><ol><li><strong>Search on Google Play and the App Store:</strong><br>Look for existing solutions related to your problem. For example, if you’re working on a solution to help you focus and avoid distractions, search for keywords like <strong>“focus”</strong> and <strong>“screen time.”</strong></li><li><strong>Download at least three apps:</strong><br>Install a few apps that match your criteria.</li><li><strong>Analyze the user journey:</strong><br>Explore how each app functions and guides users through its features.</li><li><strong>Ask yourself:</strong><br><em>What could be improved?</em> Identify gaps or areas where you can offer a better experience or solution. This will help you create a more competitive and user-friendly app.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*821AwrDZqp6QRtu5XB-KRQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yho4Hydd7AxB6cGlRQ-Ajg.jpeg" /></figure><p>Don’t be ashamed to take some inspiration from the user journey, screenshots, app description, or app marketing of existing apps. Steve Jobs once said, <strong><em>“Good artists copy; great artists steal.”</em> </strong>Jobs mentioned that Apple had always been <strong><em>“shameless about stealing great ideas.”</em></strong></p><h3>3. Decide What to Put Behind the Paywall</h3><p>When I first started, I had almost no idea what to put behind a paywall for paid users. You might also wonder whether to offer:</p><ul><li><strong>Ad-free freemium</strong></li><li><strong>Limited content for premium users</strong></li><li><strong>A free trial for new users</strong></li></ul><p>To decide, refer back to your <strong>north star</strong> from step 1 and consider what will resonate most with your target audience. If your audience is less likely to pay, starting with ads might be a better option. On the other hand, if they are higher-income users, you could try a paywall or a freemium model with very limited access.</p><p>Additionally, by analyzing competitors with a solid user base and positive reviews, you can create a roadmap. Study how these apps generate revenue and don’t hesitate to use them as inspiration. Thorough competitor research will save you time and effort when developing your own strategy.</p><p>Here are example from <a href="https://app.ertigo.me/"><strong>my app ERTIGO</strong></a><strong> </strong>on the store using a<strong> freemium model.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kHRrR0szhECwaM4S3YrGYA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rS33bhuedfFjCuRe3CK0gA.jpeg" /></figure><h3>4. Adding Paywall to Your App</h3><p>After you&#39;ve finalized your plan, it&#39;s time to implement the payment system that will trigger the <strong>native payment flow</strong> on both <strong>Android</strong> and <strong>iOS</strong> for your Flutter app. Flutter supports in-app purchases through packages like <strong>in_app_purchase</strong>, which allows you to integrate subscriptions, one-time payments, and other payment models seamlessly across both platforms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*_VtO5IugQUS-k2jgIZIj4w.png" /><figcaption>Image taken from Flutter in_app_purchase</figcaption></figure><p>At first, I planned to use the <a href="https://pub.dev/packages/in_app_purchase">in_app_purchase</a> to handle the payment, as it unifies the API for Android and iOS billing. However, after doing more research, I came across a service called <strong>RevenueCat, </strong>which has a dedicated <a href="https://pub.dev/packages/purchases_flutter">Flutter library</a> available.</p><p>After comparing the two libraries, I decided to go with <strong>RevenueCat</strong> for four reasons:</p><ul><li><strong>Easy Setup:</strong><br>RevenueCat simplifies the setup and management of payments. It allows you to focus on developing features while the platform, specialized in mobile billing and payment, handles the rest. You can configure your App Store and Play Store data through the RevenueCat backend and connect your app using an API key.</li><li><strong>Unified Insights:</strong><br>RevenueCat provides charts and dashboards that consolidate data from all platforms in one place. Since we use Flutter to develop apps for multiple platforms, this feature is crucial. For example, in my RevenueCat dashboard below, I can see transactions from both the Play Store and the App Store. While this might not seem important at the beginning, having access to metrics and data becomes invaluable later. It helps you make <strong>data-driven decisions</strong>, such as tracking whether a new feature improves the conversion rate from trial to paid users.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gXVXp5K1ZbhHbxm2a-JUXQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GHR_dFPO6hdk-YJhHsTQtQ.png" /></figure><ul><li><strong>Ready-to-Use Paywall:</strong><br>Once you’ve set up your App Store and Play Store products, you can configure the look of your paywall directly from the RevenueCat backend. This is helpful because designing your own paywall can easily violate <strong>Google Play</strong> or <strong>App Store</strong> policies. I’ve had experiences where my app was <strong>rejected</strong> and even <strong>suspended</strong> due to paywall compliance issues. Check out my article about that <a href="https://medium.com/gitconnected/lessons-learned-from-submitting-4-apps-for-review-3-approved-1-suspended-in-just-2-weeks-on-1fe6544ea9f8">here</a>. RevenueCat helps reduce this risk by ensuring the paywall adheres to platform guidelines.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tj1CNOQSjjIRcXiNDrhVug.png" /><figcaption>RevenueCat Paywall editor of my app</figcaption></figure><p>Here are some paywall templates to choose from</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*C3DYIMeNuiLWG1ydXTi96Q.png" /></figure><p>In Flutter, after completing all the setup on the <strong>RevenueCat</strong> backend and within your app, you can present a paywall with just <strong>one line of code</strong>. This paywall allows users to easily tap and make a purchase, streamlining the entire payment process.</p><pre>await RevenueCatUI.presentPaywall();</pre><h4>Here are the resource to look into</h4><ul><li><a href="https://www.youtube.com/watch?v=31mM8ozGyE8"><strong>Understanding RevenueCat</strong></a>🔗<br>Learn the terms and structure of managing in-app payments through RevenueCat.</li><li><a href="https://www.youtube.com/watch?v=31mM8ozGyE8"><strong>Setup Guide</strong></a><strong>🔗</strong><br>Follow the steps to set up and integrate RevenueCat into your app. A <a href="https://www.youtube.com/watch?v=31mM8ozGyE8"><strong>video version</strong></a>🔗 of the guide is also available for easier understanding</li></ul><h3>5. Promoting Your App And Get Your First User</h3><p>I will first cover short-term channel to promote your app. If you talking long-term there are multiple thing to do such as web funnel, ASO optimization and paid user acquisition.</p><h4>Here are channels to promote your app:</h4><p>I’ve compiled a list of channels I’ve used to promote my apps. If you know where your target audience hangs out, be sure to go there and promote your app. The following sites are commonly used by app and software developers to showcase their products, get feedback, and interact with users.</p><ul><li><a href="https://www.producthunt.com/products/neckfit-exercises-posture-corrector"><strong>ProductHunt</strong></a><strong>: </strong>I made <a href="https://www.producthunt.com/products/neckfit-exercises-posture-corrector">my first launch </a>of one of my apps, <strong>NeckFit</strong>, on <strong>Product Hunt</strong>. If you haven’t heard of it, Product Hunt is a community site for <strong>startups</strong> and <strong>makers</strong>. You can launch your product there, and the community votes on the top products of the day. The most popular product gets featured on the site’s homepage, which can attract early adopters and valuable feedback.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wl5i98JM9lE922hXSc_QwA.png" /></figure><ul><li><strong>LinkedIn</strong><br>Post updates using the <strong>#BuildInPublic</strong> tag. This tag is popular among makers and developers who share their journey of building products. It’s a great way to connect with others and gain visibility within the tech and startup communities.</li><li><a href="https://www.indiehackers.com/"><strong>Indie Hackers</strong></a>🔗<br>Indie Hackers is similar to Product Hunt but with a stronger focus on educating developers on how to monetize their software. It’s a supportive community where you can share your progress, learn from others, and get feedback.</li><li><strong>Reddit</strong><br>Reddit is excellent for promoting your app to different niche communities. There are numerous subreddits where you can share your product, but be cautious of each group’s <strong>self-promotion rules</strong> to avoid getting flagged or banned. Here are some useful subreddits to explore.</li><li><a href="https://www.reddit.com/r/iOSProgramming/">r/iOSProgramming/</a></li><li><a href="https://www.reddit.com/r/iosapps/">r/iosapps/</a></li><li><a href="https://www.reddit.com/r/SideProject/">r/SideProject/</a></li></ul><h3><strong>Conclusion &amp; Key Actions:</strong></h3><ol><li><strong>Define your problem and audience:</strong><br>Use this as your <strong>north star</strong> to guide your development and decision-making process.</li><li><strong>Research your competitors:</strong><br>Spend time analyzing how they craft their <strong>user journey</strong> and <strong>paywall display</strong>. Take inspiration from them — there’s no shame in learning from others!</li><li><strong>Decide what is free and what goes behind the paywall:</strong><br>Refer back to your <strong>north star</strong> and think carefully about which features will drive user engagement and conversions.</li><li><strong>Add the paywall:</strong><br>I highly recommend using <a href="https://www.revenuecat.com/"><strong>RevenueCat</strong></a> to simplify the setup and management of payments, and analytics</li><li><strong>Promote your app:</strong><br>Launch on various platforms, get feedback, and continually improve your app based on user input.</li></ol><p>Lastly, <strong>be patient</strong> — your first subscriber may take time, but persistence and continuous refinement will pay off.</p><p>Thanks for reading this article and follow me to stay tune for more in-depth article about each step. Feel free to <strong>connect with me on</strong></p><p><a href="https://www.linkedin.com/in/boonya-kitpitak/">LinkedIn 🔗</a></p><p><a href="https://github.com/BenBoonya">BenBoonya - Overview</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2702ad7ee16b" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/5-steps-to-earn-your-first-dollar-from-your-mobile-app-built-with-flutter-2702ad7ee16b">5 Steps to Earn Your First Dollar from Your Mobile App (Built with Flutter)</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lessons Learned from Submitting 4 Apps for Review: 3 Approved, 1 Suspended in Just 2 Weeks on…]]></title>
            <link>https://levelup.gitconnected.com/lessons-learned-from-submitting-4-apps-for-review-3-approved-1-suspended-in-just-2-weeks-on-1fe6544ea9f8?source=rss-c6b1e8a86f0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fe6544ea9f8</guid>
            <category><![CDATA[google]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Boonya Kitpitak]]></dc:creator>
            <pubDate>Wed, 18 Sep 2024 05:01:33 GMT</pubDate>
            <atom:updated>2024-09-23T00:41:17.355Z</atom:updated>
            <content:encoded><![CDATA[<h3>Lessons Learned from Submitting 4 Apps for Review: 3 Approved, 1 Suspended in Just 2 Weeks on Google Play and the App Store.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ky1206YTPcNXnbFKA7ubfg.png" /></figure><p><strong>Google Play</strong> and the <strong>App Store</strong> are the two biggest marketplaces for mobile app developers to reach millions of users worldwide. As a developer, getting your app onto these platforms is both an exciting and nerve-wracking experience. In the last two weeks, I submitted four different apps for review. Three made it through, but one got suspended.</p><p>For those new to the game, it’s worth mentioning that enrolling in the <strong>Apple Developer Program costs $99 per year</strong>, while the <strong>Google Play Developer Program charges a one-time fee of $25</strong>. Both require a small investment to get started, but the real cost is navigating the unpredictable review landscape. Here’s what I discovered along the way.</p><h4>Background</h4><p>So, my background is in native Android and Flutter development. During the pandemic, I started dealing with some pretty annoying neck, shoulder, and back pain, the kind that hit you after sitting at your desk for way too long. That’s when I discovered low-impact exercises like yoga. I started paying more attention to how I was using my body, and then, even after 10+ hours of sitting per day, I still felt ok.</p><p>That got me thinking: why not take it further? So, I signed up for a stretching coach certification from <a href="https://www.yogabody.com/flexibility-coach/">Yogabody</a> (it’s legit, certified by YACEP), and now I’m officially a certified stretching coach! With that, I decided to create an app to bring the benefits of yoga and science-based stretching to people who are in pain but don’t know where to start.</p><p>Here are 4 Apps on Android &amp; iOS that I have sent for review. All of them are created using Flutter.</p><h4><strong>1. TouchToe: Stretch &amp; Flexibility</strong> <strong>(iOS)</strong></h4><p><strong>Platform</strong>: iOS<br><strong>Status</strong>: Live<br><strong>Time to Approval:</strong> 3 days since submitted on Aug 26, 2024<br><strong>Number of Rejections:</strong> 5<br><a href="https://apps.apple.com/th/app/stretch-flexibility-touchtoe/id6648794577"><em>Check it out on App Store</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*NCujDTTHJRB9O9tpmDU5gQ.png" /></figure><p>The first app I submitted for review during this period was <strong>TouchToe: Stretch &amp; Flexibility</strong> on iOS. It went live just 3 days after I submitted the initial version. It faced 4 rejections along the way.</p><p>The first rejection was due to a crash in the app, which I quickly fixed. However, after that, I ran into several policy violations, mainly around the paywall and the naming and description of the subscription options. After making the necessary adjustments and aligning the design with Apple’s guidelines, the app finally got approved.</p><p>One thing I noticed this time around is how much faster Apple’s review process has become compared to when I released an app two years ago. The expedited review option was quick — in some cases, my app was reviewed almost immediately after I requested it.</p><h4><strong>2. TouchToe: Stretch &amp; Flexibility (Android)</strong></h4><p><strong>Platform</strong>: Android<br><strong>Status</strong>: Suspend<br><strong>Number of Rejections:</strong> 4</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EX5hDT0-zHvqL9IawPWhdg.png" /></figure><p>After I wrapped up the iOS review process, I submitted the same version of the app to Google Play. But it got rejected — and this time, I wasn’t even sure if I was dealing with a human or an automated system. The appeal process felt slow, taking over 24 hours just to get feedback.</p><p>At first, I didn’t realize that repeated rejections could lead to suspension, so I did what I had done on iOS: resubmitted the app to get more feedback. But after the fourth rejection, my app was suspended.</p><p>One thing that stood out to me was how much clearer Apple’s rejection reasons and next steps were compared to the Play Store. On Google Play, the reasons for rejection were often vague or didn’t seem to match the attached screenshots, which left me feeling pretty confused.</p><h4><strong>3. NeckFit: Posture &amp; Exercises (iOS)</strong></h4><p><strong>Platform</strong>: iOS<br><strong>Status</strong>: Live<br><strong>Time to Approval:</strong> 5 days since submitted on Sep 12, 2024<br><strong>Number of Rejections:</strong> 4<br><a href="https://apps.apple.com/th/app/neckfit-posture-exercises/id6670690205"><em>Check it out on App Store</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_EamYtBNwLRMBwArI73Q3g.png" /></figure><p>This app went live 5 days after the first submission. This time somehow the same paywall that works with the <strong>TouchToe: Stretch &amp; Flexibility </strong>doesn’t pass the review. I need to make some adjustments to pass the review but overall the reviewer is very clear on what step to take. I will make a summary point later on.</p><h4><strong>4. NeckFit: Posture &amp; Exercises (Android)</strong></h4><p><strong>Platform</strong>: iOS<br><strong>Status</strong>: Live<br><strong>Time to Approval:</strong> 23 hours since submitted on Sep 15, 2024<br><strong>Number of Rejections:</strong> 0<br><a href="https://play.google.com/store/apps/details?id=com.ertigo.forwardhead"><em>Check it out on Play Store</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*We_P2q_cIWOCHzK_4PEoow.png" /></figure><p>This time I submitted the exact same version that got approved from iOS and it somehow got approved very fast.</p><h3>5 Lessons learnt from submitting app to review on Google Play and App Store</h3><h4>1. If You Create the Same App for Android and iOS, Submit to iOS First.</h4><p>If you’re developing an app with <strong>the same functionality and design for both Android and iOS</strong>, I highly recommend <strong>submitting it to the App Store (iOS) first</strong>. On Google Play, multiple rejections can quickly lead to a suspension, which isn’t as much of a risk with Apple.</p><p>While the policies of both stores aren’t exactly the same, they’re quite similar in many areas. So, by going through the App Store’s review process first, you’re more likely to catch any issues without risking suspension. Plus, as pointed out in this<a href="https://www.reddit.com/r/androiddev/comments/1ck1wyp/did_google_play_recently_started_to_suspend_after/"> reddit post</a> I came across, dealing with rejections on the App Store tends to be a bit more straightforward than on Google Play. However, it’s also somewhat understandable, considering that Apple charges for its developer program on a yearly basis, while Google Play only collects a one-time fee.</p><h4>2. If your app gets suspended on Google Play, the fastest way to recover is to change the package name and resubmit it as a new app</h4><p>This can be quite frustrating when you have multiple integrations tied to your app’s package name, like Firebase, OneSignal, and other services. However, recovering from a suspension while keeping the same package name is a lengthy process. I’ve been waiting for the Google Play support team regarding my TouchToe app suspension, but so far, they’ve just told me to wait. I’ll keep waiting to see how long it might actually take to recover from the suspension.</p><h4>3. Be Very Detail on the paywall design and review policy violation</h4><p>You can read the guidelines on <a href="https://support.google.com/googleplay/android-developer/answer/9900533/">Google Play</a> and the<a href="https://developer.apple.com/design/human-interface-guidelines/in-app-purchase#Autorenewable-subscriptions"> App Store</a>, but from my experience with the free-trial paywall, there are two main points to keep in mind:</p><ol><li><strong>Don’t make the free trial appear more prominent or significant than the actual price.</strong> The policy states that the pricing details should be clear and transparent, without overshadowing the real cost.</li><li>Sometimes, wording matters a lot. For example, I initially used the phrase <strong>“Try for 0 USD”</strong> which got rejected because the reviewer considered it misleading. I had to change it to <strong>“Try it free”</strong> to comply with the guidelines.</li></ol><h4>4. Sometimes, the judgment on policy violations depends on the reviewer’s</h4><p>Sometimes, you might find that an app passes review quickly, while another submission with the same design or approach gets rejected. In my experience, the outcome can also depend on the reviewer’s judgment, so you may encounter some inconsistencies in the review standards from time to time.</p><h4>5. Be kind!</h4><p>When submitting your app for review, it helps to approach the process with a bit of kindness and empathy. Remember, the reviewers on the other side are people too — their job is to ensure apps meet certain standards and guidelines to create a safe, consistent experience for users. While it can be frustrating when you receive a rejection or unclear feedback, try to see it as an opportunity to improve your app and make it even better.</p><p>Be polite in your communications, whether you’re responding to feedback or requesting an expedited review. If your app gets rejected, carefully read the reviewer’s notes, and take the time to understand their perspective. A thoughtful, respectful response can go a long way.</p><p>Let me know what you think!</p><p><a href="https://www.linkedin.com/in/boonya-kitpitak/">Connect with me on LinkedIn!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fe6544ea9f8" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/lessons-learned-from-submitting-4-apps-for-review-3-approved-1-suspended-in-just-2-weeks-on-1fe6544ea9f8">Lessons Learned from Submitting 4 Apps for Review: 3 Approved, 1 Suspended in Just 2 Weeks on…</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Weekly Chart. Display data in weekly format using Flutter]]></title>
            <link>https://boonya-kitpitak.medium.com/flutter-weekly-chart-display-data-in-weekly-format-using-flutter-cd07be1ded78?source=rss-c6b1e8a86f0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd07be1ded78</guid>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <dc:creator><![CDATA[Boonya Kitpitak]]></dc:creator>
            <pubDate>Sun, 18 Jul 2021 14:25:27 GMT</pubDate>
            <atom:updated>2021-07-18T14:25:27.957Z</atom:updated>
            <content:encoded><![CDATA[<p>Long story short, I have created example app that display the data in weekly format using Flutter and I think I might be useful to other developers that might come across</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*vZGHu_xrVKbXpjrOqACFOw.png" /></figure><p>Please head toward my repository to see the code sample. Don’t forget to leave a star and follow me on Github.</p><p><a href="https://github.com/BenBoonya/flutter-weekly-chart">BenBoonya/flutter-weekly-chart</a></p><p>Here are some explanation and detail</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WgfItmET5TKFn0jzyReyFQ.gif" /><figcaption>A gif of how the app look like.</figcaption></figure><p>I came across this kind of screen in the app that I have been working on called Ergonomic Productivity Timer</p><blockquote>Ergonomic Productivity Timer is productivity timer that care for health!</blockquote><p>💁‍♂️ Get it on <a href="https://bit.ly/3pZOuEE">Google Play Store</a> and <a href="https://apps.apple.com/th/app/ergonomic-pomodoro-timer/id1550788893s">App Store</a> today!</p><p>On the statistic screen where you can view how much time you spend working, breaking and exercising. I think weekly chart which display data week by week would be appropriate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*vZGHu_xrVKbXpjrOqACFOw.png" /></figure><p>Each day in the week, the height of the chart is proportional to the fraction of each day data divided by the max value of the week. In this case, the max value of the week is on Friday so the Friday chart is at the max height. When each chart is clicked, small chip liked view display on top of the chart.</p><h3>Changing current week</h3><p>In this example app, we only display the current and the previous weeks. We also hi-light today date on current week. Suppose today is Friday, July 16th. Current week is 12 Jul — 18 Jul starting from Monday to Sunday.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*4cthQtE6VDg_bRsQm2hLyQ.png" /><figcaption>Current week state</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*bLrEPVtf40GV4c-IVP-a5A.png" /><figcaption>Previous weeks state</figcaption></figure><p>This app use <a href="https://pub.dev/packages/get">GetX</a> as state management library.</p><p>That’s it. Thanks for reading. Cheers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd07be1ded78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[อธิบายเรื่องการใช้ Kotlin Coroutines ใน Android แบบรวบรัด]]></title>
            <link>https://medium.com/black-lens/%E0%B8%AD%E0%B8%98%E0%B8%B4%E0%B8%9A%E0%B8%B2%E0%B8%A2%E0%B9%80%E0%B8%A3%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%87%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89-kotlin-coroutines-%E0%B9%83%E0%B8%99-android-%E0%B9%81%E0%B8%9A%E0%B8%9A%E0%B8%A3%E0%B8%A7%E0%B8%9A%E0%B8%A3%E0%B8%B1%E0%B8%94-1cb1706ecaa5?source=rss-c6b1e8a86f0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cb1706ecaa5</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-coroutines]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[viewmodel]]></category>
            <dc:creator><![CDATA[Boonya Kitpitak]]></dc:creator>
            <pubDate>Sat, 31 Aug 2019 06:13:21 GMT</pubDate>
            <atom:updated>2021-05-19T04:27:03.058Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*qyzIfvnTgzDwYlaw6kgmBw.jpeg" /></figure><p>ช่วงหลังๆมานี่เพื่อนๆน่าจะเคยได้ยินเรื่องของ Coroutine กันมาเยอะว่ามันดี อย่างนู้นอย่างนี้ แต่ไม่มีเวลาได้ศึกษามันอย่างจริงๆจังๆซักที ในบทความนี้ผมจะพยายามสรุปเรื่องของ Coroutine และ Concept พื้นฐานอย่างรวบรัด เผื่อเพื่อนๆคนไหนอยากเอาไปเริ่มต้นใช้งานใน Android Application ของตัวเอง</p><p>ถ้าจะว่ากันโดยย่อแล้ว Kotlin Coroutine คือการเขียน โค้ดในรูปแบบ Asynchronous ด้วยวิธีที่อ่านง่ายและกระชับขึ้นโดยไม่ต้องใช้ CallBack มากมาย</p><p>เพื่อให้ไม่เป็นการเสียเวลาลองดู Code ด้านล่างกันเลยครับ</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/080213f7ece05de5a4b84e70a8296c62/href">https://medium.com/media/080213f7ece05de5a4b84e70a8296c62/href</a></iframe><p>ใน Code จะมี ViewModel class โดย class นี้ได้ใช้ Coroutine เพื่อ Fetch ข้อมูล Object Artist จาก Api โดยการเรียก getArtistUseCaseซึ่งถูก Inject เข้ามาใน Constructor</p><p>ก่อนจะไปต่ออยากแนะนำให้รู้จักกับสิ่งสำคัญด้านล่างนี้ก่อน</p><ul><li>สิ่งแรกที่ทุกคนควรรู้จักคือ <strong>Coroutine Context</strong></li></ul><blockquote><strong>Coroutine Context </strong>ใช้เพื่อกำหนดว่าจะให้ Coroutine ของเรา Execute แบบไหน เช่น จะ Run บน UI Thread หรือ IO Thread(ส่วนใหญ่เอาไว้ยิง API) โดยการกำหนด Coroutine Context นั้นสามารถทำได้ผ่าน Dispatcher</blockquote><p>Dispatchers ที่ ใช้งานบ่อยมากๆจะมีสองแบบ Dispatchers.Main จะใช้เวลาเราต้องการให้ Coroutine ทำงานเกี่ยวกับ UI Thread , ส่วน Dispatchers.IO จะใช้กับ Task ที่จะ Block Thread ปัจจุบัน เช่น ยิง API Request, การเข้าถึง Database หรือ Files</p><ul><li>ต่อมาคือ <strong>Coroutine Builder </strong>เจ้าตัวนี้ใช้สร้าง Coroutine ใหม่ขึ้นมาโดยหลักๆแล้วจะมี Builder ที่สำคัญอยู่ 3 ตัว</li></ul><ol><li>launch: launch เรียกได้ว่าเป็น Builder ที่ถูกใช้บ่อย เพราะเป็นวิธีที่ง่ายที่สุดในการสร้าง Coroutine โดย Coroutine ที่ถูกสร้างขึ้นจะไม่ไป Block Thread ที่กำลัง ทำงานอยู่</li><li>async : async เป็น Builder ที่สามารถ Return ค่าออกมาจาก Coroutine ได้ โดยจะยังไม่ขอพูดเรื่อง builder ตัวนี้ในเชิงลึก ถ้ามีโอกาสจะเล่าให้ฟังในบทความต่อๆไป</li><li>runBlocking : ต่างจาก launch runBlocking จะ block Thread ที่กำลังทำงานอยู่ (ฟังแล้วอาจดูแปลกๆเพราะ จุดประสงค์ของ Coroutine คือการทำงานแบบ Asynchoronous ไม่ใช่เหรอ? แต่จริงๆแล้ว runBlocking มีประโยชน์มากเวลาเขียน test ให้กับ Coroutine นั่นเอง)</li></ol><p>ทีนี้กลับมาที่ตัวอย่างของเรากัน เราจะมาสร้าง Coroutine เพื่อดึงข้อมูลมาจาก API กัน</p><p>การจะสร้าง Coroutine ขึ้นมานั้นเราต้องกำหนด <strong>Coroutine Context </strong>ให้กับ <strong>Coroutine Builder</strong> ของเรากันก่อน ในตัวอย่างของเรานี้ เรากำหนด Coroutine Context โดยใช้ CoroutineScope</p><pre>class ArtistViewModel( <br>    private val getArtistsUseCase: GetArtistsUseCase<br>): ViewModel(), <strong>CoroutineScope</strong> {</pre><pre>   private val job = Job() <br>    <br>   override val coroutineContext: CoroutineContext        <br>        get() = job + Dispatchers.Main</pre><pre>    ...</pre><pre>    override fun onCleared() {<br>        super.onCleared()<br>        job.cancel()<br>    }<br>}</pre><p>ในที่นี้เราให้ class ArtistViewModel implement CoroutineScope ซึ่งเราก็จะต้อง override coroutineContext ด้วย ซึ่งนี้เป็นการกำหนด <strong>Coroutine Context </strong>ให้กับ Coroutine ใน ViewModel ของเรา</p><pre>override val coroutineContext: CoroutineContext        <br>        get() = job + Dispatchers.Main</pre><p>การประกาศแบบนี้ เป็นการบอกว่า Default Dispatcher ของ Coroutine ใน Class นี้คือ Dispatchers.Main (ย้ำกันอีกทีว่า Dispatcher.Main คือการกำหนดให้ Coroutine ทำงานบน UI Thread)และ การที่มี job นั้นทำให้เราสามารถ เรียกjob.cancel() ได้ทุกเมื่อเวลาที่เราต้องการยกเลิก การทำงานของ Coroutine ที่อยู่ใน Class นี้</p><p>ในที่นี้เราจะเรียก job.cancel() ใน function onCleared() เพื่อให้ Coroutine ของเราหยุดทำงานในกรณีที่ viewModel โดนทำลายไป</p><p>หลังจากการกำหนด Scope ของ Coroutine กันไปแล้วเราก็มาเริ่มสร้าง Coroutine กันเลย</p><pre>launch {    <br>    val response = <strong>withContext</strong>(Dispatchers.IO) {       <br>        getArtistsUseCase(&quot;Slayer&quot;)            <br>    } <br>            <br>    artistsLiveData.value = response?.result<br>}</pre><p>ในที่นี้ต้องเราเรียก getArtistsUseCase(“Slayer”) ซึ่งเป็น UseCase ที่ไปเรียก API เพื่อให้ได้ response ที่เราต้องการกลับมา ซึ่งอย่างที่บอกไปข้างต้นว่าเราต้องใช้ Dispatcher.IO ถ้าต้องการทำ task ที่เกี่ยวข้องกับการเรียก API ดังนั้นเราจึงต้องเปลี่ยน <strong>Coroutine Context</strong> จาก Default เราตั้งไว้เป็น Dispatcher.Main ให้กลายเป็นDispatcher.IO ก่อนด้วย function <strong>withContext</strong></p><p>จากนั้นพอเราได้ response กลับมาจาก Server ค่าของมันก็จะถูก Assign ลง artistsLiveData เท่านี้ก็เรียบร้อย</p><p>ในตัวอย่างที่กล่าวไปนี้สามารถนำ Concept ไปประยุกต์ใช้กับอย่างอื่นที่ไม่ใช่ viewModel ได้เหมือนกัน ไม่ว่าจะเป็นใน Presenter, Activity, หรือ Fragment</p><p>จริงๆแล้วถ้าเราใช้ Android ViewModel ใน <a href="https://developer.android.com/jetpack/androidx/releases/lifecycle">AndroidX lifecycle v2.1.0</a> ได้มีการเพิ่ม viewModelScope<strong> </strong>ทำให้เราไม่ต้องไปเรียก job.cancel() เองใน onClear() ด้วยล่ะ โดย default แล้ว Coroutine context ของ viewModelScope<strong> </strong>จะถูกกำหนดเป็น <em>Dispatchers.Main </em>สามารถดูตัวอย่างการใช้งานได้ตามด้านล่างนี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01ce789dce9cfef16ba8feeec2030699/href">https://medium.com/media/01ce789dce9cfef16ba8feeec2030699/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*t4wIFNsetFF7CrwyMkfUhg.png" /></figure><p>ส่วนใครที่อยากลอง ดู Code แล้วลองเล่นดูก็สามารถเข้าไปดูได้ที่ Link นี้เลยนะครับ</p><ol><li>แบบไม่ใช้ viewModelScope</li></ol><p><a href="https://github.com/BenBoonya/simple-coroutine-in-android-demo">BenBoonya/simple-coroutine-in-android-demo</a></p><p>2. แบบที่ใช้ viewModelScope</p><p><a href="https://github.com/BenBoonya/simple-coroutine-in-android-demo/tree/viewmodel-scope">BenBoonya/simple-coroutine-in-android-demo</a></p><p>ถ้าชอบก็กด ⭐️ ไว้ที่ repository กันหน่อยนะคร๊าบ</p><p>ก่อนจากกันก็ขอฝาก page ด้วย</p><p>รบกวนกดติดตาม และ Like Page <strong>“โค้ดไม่คิด”</strong> ตามลิงค์ด้านล่างได้เลยครับ เพื่อรอรับข่าวสารได้เลยครับ 😀</p><p><a href="https://www.facebook.com/codewithoutbrain/">https://www.facebook.com/codewithoutbrain/</a></p><p><strong>💁‍♂️ อยากเพิ่ม Productivity ในการทำงานรึเปล่า? <br></strong>ลองใช้แอป Ergo Pomodoro ที่พัฒนาโดย page ของเรากันเถอะ แอปนี้ใช้การจับเวลาแบบ Pomodoro เพื่อเพิ่มประสิทธิภาพการทำงานให้ดียิ่งขึ้น</p><p>✅ Android: <a href="http://bit.ly/3pZOuEE">bit.ly<strong>/3pZOuEE</strong></a><strong><br></strong>✅ iOS: <a href="https://apps.apple.com/us/app/ergonomic-pomodoro-timer/id1550788893">https://apps.apple.com/us/app/ergonomic-pomodoro-timer/id1550788893</a></p><h4>Follow me on Github!</h4><p><a href="https://github.com/benBoonya">https://github.com/benBoonya</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cb1706ecaa5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/black-lens/%E0%B8%AD%E0%B8%98%E0%B8%B4%E0%B8%9A%E0%B8%B2%E0%B8%A2%E0%B9%80%E0%B8%A3%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%87%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89-kotlin-coroutines-%E0%B9%83%E0%B8%99-android-%E0%B9%81%E0%B8%9A%E0%B8%9A%E0%B8%A3%E0%B8%A7%E0%B8%9A%E0%B8%A3%E0%B8%B1%E0%B8%94-1cb1706ecaa5">อธิบายเรื่องการใช้ Kotlin Coroutines ใน Android แบบรวบรัด</a> was originally published in <a href="https://medium.com/black-lens">Black Lens</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Thai] Android Single-Activity Architecture แค่ Activity เดียวก็พอแล้ว?]]></title>
            <link>https://medium.com/black-lens/thai-android-single-activity-architecture-%E0%B9%81%E0%B8%84%E0%B9%88-activity-%E0%B9%80%E0%B8%94%E0%B8%B5%E0%B8%A2%E0%B8%A7%E0%B8%81%E0%B9%87%E0%B8%9E%E0%B8%AD%E0%B9%81%E0%B8%A5%E0%B9%89%E0%B8%A7-253b6db371e5?source=rss-c6b1e8a86f0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/253b6db371e5</guid>
            <category><![CDATA[android-jetpack]]></category>
            <category><![CDATA[fragments]]></category>
            <category><![CDATA[activity]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-architecture]]></category>
            <dc:creator><![CDATA[Boonya Kitpitak]]></dc:creator>
            <pubDate>Mon, 17 Jun 2019 04:04:36 GMT</pubDate>
            <atom:updated>2021-03-02T01:36:25.226Z</atom:updated>
            <content:encoded><![CDATA[<h3>Android Single-Activity Architecture แค่ Activity เดียวก็พอแล้ว?</h3><p>Activity เป็นสิ่ง Android developer ทุกคนคุ้นเคยกันเป็นอย่างดี และ Activity ก็อาจเป็นสิ่งแรกที่เราได้เรียนรู้ ในการศึกษาการพัฒนา Application Android เลยด้วยซ้ำ และใน Application ที่เราพัฒนากัน จะมี Activity มากหรือน้อยก็ขึ้นอยู่กับความซับซ้อนและ Design</p><p>ใน Google I/O 2018 พร้อมๆกับการประกาศตัวของ Jetpack ก็ได้มีการกล่าวถึงเรื่องของ Single Activity Architecture ขึ้นมา โดยจากเนื้อหาแล้วก็เหมือนว่า Google เชียร์ให้ใช้ Architecture นี้ด้วย</p><blockquote>Today we are introducing the Navigation component as a framework for structuring your in-app UI, with a focus on making a single-Activity app the preferred architecture.</blockquote><p>(<a href="https://android-developers.googleblog.com/2018/05/use-android-jetpack-to-accelerate-your.html?m=1">https://android-developers.googleblog.com/2018/05/use-android-jetpack-to-accelerate-your.html?m=1</a>)</p><p>โดยย่อแล้ว Single-Activity Architecture คือ Architecture ที่ใน Application จะ<strong>มีเพียง Activity เดียว </strong>โดยแทนที่เราจะใช้ หนึ่ง Activity ต่อหนึ่ง Screen เราจะ มี Activity เป็นเหมือน Container ใหญ่ๆเพียงแค่ตัวเดียว และ Screen ต่างๆใน Application ก็จะเป็น Fragment แทน</p><p>แล้วทำไมเราถึงควรใช้ Single Activity Architecture ล่ะ การใช้ Activity หลายๆตัวในแบบที่เราเคยทำมามีปัญหาอะไร?</p><ol><li><strong>เคยไหมกับการต้องเขียน Activity ที่มีเพียง Fragment เดียว โดยทำไปเพราะเค้าบอกกันว่าเป็น Best Practice?</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*GBB_IrB2B665nr_zAmo8Wg.jpeg" /></figure><p>(อันนี้ความเห็นส่วนตัวผมนะครับ ไม่ได้จะบอกว่าถูกหรือผิด 😀)</p><p>จริงอยู่ที่การใช้ Fragment ใน Activity เป็น Best Practice และ ทำให้เราสามารถ Reuse Fragment นั้นใน Activity อื่นได้ แต่ถ้าเราพูดถึง UI ที่ใช้เพียงที่เดียวโดยไม่มีการ Reuse ที่อื่นเลย การสร้าง Activity โดยมี Fragment ข้างในเพียงหนึ่งตัวนี่ยังจำเป็นอยู่รึเปล่า? หรือเราควรสร้าง Activity เปล่าแบบที่ไม่มี Fragment ไปเลยจะดีกว่า</p><p>แต่ถ้าเราใช้ Single Activity Architecture ก็ไม่ต้องมานั่งสร้าง Activity มาครอบ Fragment ไม่ว่าจะเพียง Fragment เดียวหรือหลาย Fragment อีกต่อไป เพราะ Application ของเราจะมีเพียง Activity เดียว</p><p>2. <strong>ปัญหาของ Transition Animation ระหว่าง Activity</strong></p><p>สังเกตุตรง Status Bar ขณะที่มีการ Transition ระหว่าง Activity มันจะกระพิบ</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FWXVywnBSjAo%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DWXVywnBSjAo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FWXVywnBSjAo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4677f5eb7f3c75046654f96fcd1c3cf7/href">https://medium.com/media/4677f5eb7f3c75046654f96fcd1c3cf7/href</a></iframe><p>ซึ่งการแก้ไขปัญหานี้ก็ไม่ตรงไปตรงมาซะทีเดียว ต้องเพิ่ม Code ที่ต้องพูดว่า <strong>ไม่บอกก็ไม่รู้นะเนี่ย</strong> เข้าไปหลายบรรทัดอยู่เหมือนกัน สามารถอ่านวิธีแก้ไข Status Bar กระพิบตอนใช้ Shared Element Transition ได้ที่นี่ <a href="https://mikescamell.com/shared-element-transitions-part-5/">https://mikescamell.com/shared-element-transitions-part-5/</a></p><p>แต่ปัญหานี้จะไม่เกิดขึ้นใน Transition ระหว่าง Fragment</p><p>3. <strong>การแชร์ข้อมูลกันระหว่าง Activity</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WjXG2CEGG_3CDk6vswiRdw.png" /></figure><p>เวลาที่เราจะแชร์ข้อมูลระหว่าง Activity โดยส่วนใหญ่แล้วเราก็จะเอาข้อมูลนั้นไปใส่ใน Singleton Data Holder เช่น Application Class แต่ปัญหามันอยู่ที่ว่า Singleton Data Holder นี้เนี่ยมันอยู่ในระดับ Application Scope ซึ่งเป็น Scope ที่ Service หรือ Content Provider สามารถเข้าถึงได้เช่นกัน แต่เราต้องการแชร์ข้อมูลระหว่าง Activity ไม่ได้ต้องการแชร์ กับ Service หรือ Content Provider ซักหน่อย</p><p>ถ้าอย่างนั้น Single Activity Architecture สามารถช่วยเราได้อย่างไรล่ะ? ลองดูรูปต่อไปนี้ครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VSXfNBCsxa3_wCOAqR88aQ.png" /></figure><p>เมื่อเราใช้ Single Activity Architecture การแชร์ข้อมูลกันก็จะเกิดขึ้นในระดับ Fragment แทนและการแชร์ข้อมูลทั้งหมดก็จะถูกครอบด้วย Activity ซึ่ง ทำให้ข้อมูลนั้นถูก Scope แยกออกจาก Application Scope และไม่สามารถเข้าถึงได้จาก Service หรือ Content Provider นั่นเอง</p><p>ถ้าอย่างนั้นเราจะเริ่มเขียน Single Activity Architecture กันยังไงดีล่ะ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*ovlYHtqVf9fpy1GzeHhPJw.jpeg" /></figure><p>การเขียน Application ในรูปแบบ Single Activity Architecture นั้นไม่ได้ยากอย่างที่คิดเพียงเราใช้ <strong>Jetpack’s Navigation Component</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OteZWhxW2da2J-Bu_D9IeA.png" /></figure><p>เนื่องจากบทความเรี่อง <strong>Jetpack’s Navigation Component </strong>น่าจะมีเนื้อหาค่อนข้างเยอะจึงขออนุญาติแยกไว้เป็น อีกบทความหนึ่ง(ซึ่งตอนนี้กำลังปั่นอยู่ 😅)</p><p>รบกวนกดติดตาม</p><p>และ Like Page <strong>“โค้ดไม่คิด”</strong> ตามลิงค์ด้านล่างได้เลยครับ เพื่อรอรับข่าวสารได้เลยครับ 😀</p><p><a href="https://www.facebook.com/codewithoutbrain/">https://www.facebook.com/codewithoutbrain/</a></p><p><strong>💁‍♂️ อยากเพิ่ม Productivity ในการทำงานรึเปล่า? <br></strong>ลองใช้แอป Ergo Pomodoro ที่พัฒนาโดย page ของกันกันเถอะ แอปนี้ใช้การจับเวลาแบบ Pomodoro เพื่อเพิ่มประสิทธิภาพการทำงานให้ดียิ่งขึ้น ใช้งานฟรี!ดาวน์โหลดกันได้เลย</p><p>✅ Android: <a href="http://bit.ly/3pZOuEE">bit.ly<strong>/3pZOuEE</strong></a><strong><br></strong>✅ iOS: <a href="https://apps.apple.com/us/app/ergonomic-pomodoro-timer/id1550788893">https://apps.apple.com/us/app/ergonomic-pomodoro-timer/id1550788893</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=253b6db371e5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/black-lens/thai-android-single-activity-architecture-%E0%B9%81%E0%B8%84%E0%B9%88-activity-%E0%B9%80%E0%B8%94%E0%B8%B5%E0%B8%A2%E0%B8%A7%E0%B8%81%E0%B9%87%E0%B8%9E%E0%B8%AD%E0%B9%81%E0%B8%A5%E0%B9%89%E0%B8%A7-253b6db371e5">[Thai] Android Single-Activity Architecture แค่ Activity เดียวก็พอแล้ว?</a> was originally published in <a href="https://medium.com/black-lens">Black Lens</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 เหตุผลที่ Android Developer ควรจะเปลี่ยนมาใช้ Kotlin]]></title>
            <link>https://medium.com/skooldio/android-java-to-kotlin-aed5b4eb15d0?source=rss-c6b1e8a86f0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/aed5b4eb15d0</guid>
            <category><![CDATA[google-android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Boonya Kitpitak]]></dc:creator>
            <pubDate>Sat, 11 May 2019 05:50:09 GMT</pubDate>
            <atom:updated>2019-05-11T06:00:47.235Z</atom:updated>
            <content:encoded><![CDATA[<p>ณ ปี 2019 นี้เชื่อว่าคงไม่มีใครในสายงาน Android Developer ที่ไม่เคยได้ยินชื่อของ Kotlin แล้ว โดยล่าสุดในงาน Google I/O 2019 ทาง Android Team ของ Google ก็ออกมาประกาศว่าแนวโน้มของ Android Development จะเป็นไปในแบบ Kotlin-First หรือมีการให้ความสำคัญกับ Kotlin มากกว่านั่นเอง</p><blockquote>“We’re announcing that the next big step that we’re taking is that we’re going Kotlin-first,” Chet Haase</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lu_WvtBM7egvJ9Y_qSrbaw.png" /><figcaption>รูปในงาน Google I/O 2019 ขณะที่ คุณ Romain Guy ถามว่ามีใครใช้ Kotlin บ้าง</figcaption></figure><p>ตัวผมเองได้เริ่มเรียนรู้และใช้งาน Kotlin มานับจากที่ทาง Google ได้ประกาศให้ Kotlin เป็น First class citizen language นับตั้งแต่ Google I/O 2017 และผมก็ขอมาตอกย้ำอีกเสียงนึงว่า Kotlin จะทำให้ ชีวิตการ Coding ของคุณดีขึ้นจริงๆนะ</p><p>ในบทความนี้ผมจะไม่ขอลงลึกด้าน Technical ถ้าจะให้ลงลึกถึงข้อดีของตัวภาษา ก็อาจจะต้องใช้เวลาเป็นวันกว่าจะบอกกล่าวกันได้หมด แต่ผมจะให้ขอข้อมูลและสาระน่ารู้เพื่อเป็นการประกอบการตัดสินใจเผื่อท่านไหนยังลังเลว่าควรจะเริ่มศึกษา Kotlin ดีหรือไม่</p><p>ผมขออนุญาตเริ่มต้นด้วย Fun Facts เกี่ยวกับ Kotlin สักเล็กน้อย</p><blockquote><strong>Kotlin ถูกใช้ในการทำงานบน Platform Android มากที่สุด</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rpiuJyojc_3gzi0Tp8z-Dw.png" /></figure><p>จากผลสำรวจล่าสุดของ Website <a href="https://pusher.com/state-of-kotlin">https://pusher.com/state-of-kotlin</a> ได้แสดงให้เห็นว่า Kotlin ได้ถูกนำมาใช้ใน Platform Android สูงที่สุด</p><blockquote><strong>Kotlin ได้รับการโหวตให้เป็นภาษาที่ได้รับความรักมากที่สุดเป็นอันดับ 2 ❤️</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I-JFyXkCbsgf7I6Z5R25kw.png" /></figure><p>ข้อมูลอ้างอิงจาก Stack Overflow Developer Survey 2018</p><p><a href="https://insights.stackoverflow.com/survey/2018/#most-loved-dreaded-and-wanted">Stack Overflow Developer Survey 2018</a></p><p>ข้อมูลที่กล่าวมาได้แสดงให้เห็นว่า ได้มีการใช้ Kotlin ใน community ของ Android Developer อย่างแพร่หลาย และ ยังได้รับ Feedback จาก community โดยรวมที่ดีทีเดียว</p><p>ส่วนเหตุผลหลักๆที่ Android Developer ควรจะเริ่มศึกษาและใช้งาน Kotlin ผมได้สรุปมา 5 ข้อต่อไปนี้</p><ol><li><strong>Official Document, Sample Project และ Libraries จาก Google มีแนวโน้มที่จะ Support Kotlin มากขึ้น</strong></li></ol><p>นี่เป็นรูปภาพของหน้า website <a href="https://developer.android.com/">https://developer.android.com</a> ที่ผมได้ Capture ไว้เมื่อปลายปี 2018</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*VdulivJ1z4eGU16QeXKjng.png" /><figcaption><a href="https://developer.android.com/">https://developer.android.com</a></figcaption></figure><p>ลองสังเกตบริเวณด้านขวาล่างของรูปภาพ (ขออนุญาตซูมให้ดูชัดๆ)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*bmt8Nm-5IYG85kUMYFDtnQ.png" /></figure><p>อย่างที่คุณผู้อ่านน่าจะ สังเกตเห็นว่านี่มัน Icon ของ Kotlin นี่นา!</p><p>ตอนนั้นไม่แน่ใจเหมือนกันว่า Google ต้องการจะสื่ออะไรจากการใส่ Icon นี้เข้ามา แต่ ณ ขณะนี้ก็คงถือว่าชัดเจนแล้วล่ะครับ จากการประกาศในงาน I/O 2019</p><p>ขณะที่เปิด Document อะไรก็ตามในหน้า Website ของ <a href="http://developer.android.com/training">developer.android.com/training</a> จะมี option ให้เลือก sample code ทั้ง Kotlin และ Java แต่ Kotlin จะขึ้นมาเป็นภาษา default เลย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RefNpwy41Ax1OAFdWnASDA.png" /></figure><p>ยิ่งไปกว่านั้นตัว Code ของ Application Google I/O 2018 ก็ยังเป็น Pure Kotlin Project อีกด้วย <a href="https://github.com/google/iosched">https://github.com/google/iosched</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*HZJm3PASZPPk62iE8AsV1A.png" /></figure><p>เท่านั้นยังไม่พอ ตัว Libray ใหม่ Jetpack Compose (<a href="https://developer.android.com/jetpack/compose">https://developer.android.com/jetpack/compose</a>) ที่เพิ่งเปิดตัวไปใน Google I/O 2019 ก็สร้างขึ้นมาสำหรับคนที่ใช้ Kotlin โดยเฉพาะเลย</p><p>โดยสรุปแล้วก็คือ เนื่องจาก Google ได้ประกาศว่า Android Development จะเป็นไปในทาง Kotlin-First แล้ว ดังนั้น Official Document ของ Android, ตัว Sample Project และ Library ใหม่ๆ ที่ออกมากจากทาง Google จะเอนเอียงไปทาง Kotlin มากกว่า</p><p><strong>2. ทางทีมพัฒนามีการ Optimize Performance สำหรับ Kotlin อย่างต่อเนื่อง</strong></p><p>อ้างอิงจาก Android Developer Blog (<a href="https://android-developers.googleblog.com/2018/08/introducing-android-9-pie.html">https://android-developers.googleblog.com/2018/08/introducing-android-9-pie.html</a>)</p><p>มี section หนึ่งใน Blog เขียนเอาไว้ว่า</p><blockquote>We’ve made an enduring commitment to Kotlin in Android and continue to expand support including optimizing the performance of Kotlin code. In Android 9, you’ll see the first results of this work — we’ve improved several compiler optimizations, especially those that target loops, to extract better performance.</blockquote><p>นั่นหมายความว่า Application ที่เขียนด้วย Kotlin จะ Compile ด้วย Performance ที่ดีขึ้นในขณะที่ Run บน Android 9 โดยเฉพาะในส่วนของ code ที่เป็น Loop สิ่งที่ท่านผู้อ่านจะต้องทำก็เพียงแค่ update Android Studio’s Kotlin plugin เพื่อที่จะได้รับ Improvement ใหม่ๆเท่านั้นเอง</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F5435391&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fwowmeme-wow-gif-5435391&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2Fff85168a136ba83e4c4d112f0d019fc0%2Fraw&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/016a00328c66b2de5088ded00e8bf2b3/href">https://medium.com/media/016a00328c66b2de5088ded00e8bf2b3/href</a></iframe><p><strong>3. Java กับ Kotlin สามารถทำงานร่วมกันได้ 100%</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*3MH9b415Ou-v9bfMHDCJSQ.jpeg" /><figcaption><a href="https://www.simplifiedtechy.net/why-switch-to-kotlin/">https://www.simplifiedtechy.net/why-switch-to-kotlin/</a></figcaption></figure><p>ถึงแม้ว่า Project ที่ท่านผู้อ่านกำลังพัฒนา หรือ ว่า ทำงานด้วย อยู่นั้นจะถูกเขียนบน Java ทั้งหมดก็ไม่แปลว่า Project นั้นจะไม่สามารถนำ Kotlin มาใช้ได้เนื่องจาก เราสามารถเรียก Function ที่เขียนบน Java จาก Class ที่เป็น Kotlin ได้ และในทางกลับกัน เราก็สามารถเรียก Function ที่เขียนบน Kotlin จาก Class ที่เป็น Java ได้เช่นกัน</p><p>ดังนั้นในกรณีที่มี Feature ใหม่ ที่ต้องเพิ่มลงไปใน Project ของเรา เราก็สามารถสร้าง Kotlin Class เพิ่มขึ้นมาได้เลย! อีกทั้ง เราก็สามารถใช้ Library ที่ใช้ Java เขียนได้เช่น Retrofit, Glide และ Library สุดโปรดของเราอีกมากมาย</p><p>แต่ทั้งนี้ทั้งนั้น ก็จะมี Feature ของ Kotlin บางส่วนที่สามารถใช้ได้เวลาถูกเรียกจาก Class ที่เป็น Java แต่ก็ไม่ได้เป็นอุปสรรคใหญ่อะไรมากนักในการทำงาน</p><p><strong>4. Kotlin นั้นเรียนรู้ได้ง่าย</strong></p><p>Kotlin นั้นไม่ใช่ภาษาที่จู่ๆ ก็ถูกสร้างขึ้นด้วยหลักการใหม่แต่อย่างใด ถ้าหากท่านผู้อ่านเคยทำงานกับ Java และมีความเข้าใจ Concept ของ OOP(Object Oreinted Programming) แล้วมาลอง เขียน Code Kotlin ดูก็น่าจะเข้าใจได้อย่างไม่ยากเย็นเลย ดังตัวอย่าง Snippet ง่ายๆด้านล่างนี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1643072eadb0c72772f176a43faa5de6/href">https://medium.com/media/1643072eadb0c72772f176a43faa5de6/href</a></iframe><p>ด้วยความรู้ในภาษา Java จะเห็นได้ว่าเราสามารถอ่านและทำความเข้าใจ Snippet ด้านบนได้ โดยจะมีความแตกต่างในเรื่องการประกาศ function และตัวแปรเล็กน้อยเท่านั้นเอง</p><p><strong>5. การเริ่มเขียน Kotlin บน Android เป็นจุดเริ่มต้นสู่สิ่งใหม่ๆ</strong></p><p>ถึงแม้ว่าในปัจจุบัน Kotlin จะถูกใช้งานในการพัฒนาบน Platform มากที่สุด แต่จริงๆแล้วยังมีอีกหลายสิ่งหลายอย่างที่ Kotlin สามารถนำไปใช้พัฒนาได้ เช่น</p><ul><li><strong>Kotlin JS</strong>: ด้วยตัว Technology Kotlin JS จะทำให้ Kotlin สามารถ compile เป็น Javascript ได้ (<a href="https://kotlinlang.org/docs/reference/js-overview.html">https://kotlinlang.org/docs/reference/js-overview.html</a>)</li><li><strong>Kotlin/Native for Native</strong>: Technology นี้ทำให้ Kotlin สามารถ compile Native Binary Code ได้ซึ่งจะ Support การ Run บน Platform ต่างๆดังนี้ <strong>iOS</strong> (arm32, arm64, emulator x86_64), <strong>MacOS</strong> (x86_64), <strong>Android</strong> (arm32, arm64),<strong> Windows</strong> (mingw x86_64),<strong> Linux</strong> (x86_64, arm32, MIPS, MIPS little endian), <strong>WebAssembly </strong>(wasm32 )(<a href="https://kotlinlang.org/docs/reference/native-overview.html#kotlinnative-for-native">https://kotlinlang.org/docs/reference/native-overview.html#kotlinnative-for-native</a>)</li><li><strong>Multiplatform Project</strong>: Technology นี้จะทำให้ iOS และ Android สามารถ Share Code บางส่วนร่วมกันได้</li></ul><p>ผมคิดว่าการเริ่มต้นเรียนรู้สิ่งใหม่ๆ จากสิ่งที่เราคุ้นเคยอยู่แล้ว นั้นจะทำให้เราเรียนรู้ได้รวดเร็วยิ่งขึ้น ดังนั้นการเริ่มเขียน Application Android ด้วย Kotlin ก็จะน่าจะทำให้เราสามารถเรียนรู้ Kotlin ได้รวดเร็วยิ่งขึ้นเช่นกัน และ เราก็สามารถต่อยอดความรู้ที่มีใน Kotlin ไปประยุกต์ใช้ในการพัฒนาบน Platform อื่นๆได้ เสมือนว่า Kotlin นั้นเป็น ยานพาหนะพาเราไปสู่โลกใหม่ๆใน ฐานะ Developer นั่นเอง</p><p><strong>สรุป</strong></p><p>ในปัจจุบัน ผมนี้คิดว่า Kotlin เป็นอีกหนึ่ง Skill ที่ Android Developer ทุกคนควรจะเรียนรู้ และ มีติดตัวไว้ เนื่องหลายๆปัจจัย ทั้งเรื่อง ความสามารถและความสวยงามของตัวภาษา, แนวโน้มการ Support ด้าน Documentation และด้านอื่นๆ จาก Google และ การนำไปประยุกต์ใช้กับ Platform อื่นๆ</p><p>สำหรับคนที่คุ้นเคยกับภาษา Java อยู่แล้วยิ่งไม่ต้องเป็นกังวล การเริ่มต้นเขียน Kotlin นั้นไม่ใช่เรื่องยากอย่างที่คิด 😀</p><p><strong>Android Developers คนไหนที่เขียน Java และสนใจอยากจะเริ่มหัดเขียน Kotlin</strong></p><p>ดูรายละเอียด Workshop: Java to Kotlin for Android Developers ได้<a href="https://v1.skooldio.com/courses/kotlin-for-android-2">ที่นี่</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rP791O8pJdka7OwY.png" /><figcaption><a href="https://v1.skooldio.com/courses/kotlin-for-android-2">https://v1.skooldio.com/courses/kotlin-for-android-2</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JjMVAbfDVuVdN7DoGP5X-g@2x.png" /><figcaption>ไม่อยากพลาดสาระดีๆ แบบนี้ ติดตามพวกเราได้ที่ FB เพจ <a href="http://www.facebook.com/skooldio">Skooldio</a></figcaption></figure><h4>Source</h4><ul><li><a href="https://techcrunch.com/2019/05/07/google-launches-jetpack-compose-an-open-source-kotlin-based-ui-development-toolkit/">https://techcrunch.com/2019/05/07/google-launches-jetpack-compose-an-open-source-kotlin-based-ui-development-toolkit/</a></li><li><a href="https://techcrunch.com/2019/05/07/kotlin-is-now-googles-preferred-language-for-android-app-development/">https://techcrunch.com/2019/05/07/kotlin-is-now-googles-preferred-language-for-android-app-development/</a></li><li><a href="https://medium.com/@magnus.chatt/why-you-should-totally-switch-to-kotlin-c7bbde9e10d5">https://medium.com/@magnus.chatt/why-you-should-totally-switch-to-kotlin-c7bbde9e10d5</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aed5b4eb15d0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/skooldio/android-java-to-kotlin-aed5b4eb15d0">5 เหตุผลที่ Android Developer ควรจะเปลี่ยนมาใช้ Kotlin</a> was originally published in <a href="https://medium.com/skooldio">Skooldio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handle Complex Navigation Flow with Single-Activity and Android Jetpack’s Navigation component]]></title>
            <link>https://proandroiddev.com/handle-complex-navigation-flow-with-single-activity-and-android-jetpacks-navigation-component-6ad988602902?source=rss-c6b1e8a86f0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ad988602902</guid>
            <category><![CDATA[navigation-component]]></category>
            <category><![CDATA[android-jetpack]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[architecture-components]]></category>
            <dc:creator><![CDATA[Boonya Kitpitak]]></dc:creator>
            <pubDate>Tue, 07 May 2019 14:05:52 GMT</pubDate>
            <atom:updated>2021-05-19T04:25:25.925Z</atom:updated>
            <content:encoded><![CDATA[<h3>Handle Complex Navigation Flow with Single-Activity Architecture and Android Jetpack’s Navigation component</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eAszXPdxvE58oKXhq02H9A.jpeg" /><figcaption><a href="https://www.creativity103.com/collections/Lightfantastic/slides/light_spaghetti.html">https://www.creativity103.com/collections/Lightfantastic/slides/light_spaghetti.html</a></figcaption></figure><p>As Android Developer you may have heard of <strong>Android Navigation Components</strong> which has been announced in Google I/O 2018. This library has just reached a stable version in March 2019. Therefore, this might be a good time to start trying it out. The current Application that I’ve been working on is utilizing a S<strong>ingle-Activity Architecture</strong> as well as Architecture Component <strong>ViewModel </strong>and <strong>LiveData</strong>. In this article, I would like to demonstrate how to handle complex application flow using the <strong>Android Navigation Components.</strong></p><p>Before we begin, I’ll assume that you have some basic knowledge of Android Navigation Component. Here are some articles that might be able to get you to start.</p><ul><li><a href="https://www.raywenderlich.com/6014-the-navigation-architecture-component-tutorial-getting-started">The Navigation Architecture Component Tutorial: Getting Started</a></li><li><a href="https://proandroiddev.com/playing-with-navigation-architecture-components-a7296f8d38f2">Playing with Navigation Architecture Components</a></li><li><a href="https://proandroiddev.com/navigation-architecture-component-for-the-rest-of-us-faafa890e5">Navigation Architecture Component for the Rest of Us</a></li></ul><p>If you have somemore time taking Google Code Lab is a good idea.</p><p><a href="https://codelabs.developers.google.com/codelabs/android-navigation/#0">Jetpack Navigation</a></p><p>Let’s kick off with the real situation that I’ve faced 😀</p><p>Let’s say that you have to create an app that has an authentication system then after the users go through a set of authentication-related screens and successfully log in to the application, they will be navigated to different flow base on their user type. Please refer to the picture below for a more precise explanation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HJCbuub8jg-VakdO4pcY7w.png" /></figure><p>Without Navigation Component, we would have to create a bunch of Activities that might be with or without Fragments. At this point, you might have a question.</p><h4>Is Single Activity really enough?</h4><p>The first question coming into my mind when I started using this library is <em>“Is having one activity like the recommended single-activity architecture is really enough for handling a complex application flow?”</em>. Eventually, I realized that the key to solving the complicated flow with only one Activity is the way we define a <em>navigation graph.</em></p><blockquote>A <strong><em>navigation graph</em></strong> is a resource file that contains your destinations and actions. The graph represents your app’s navigation paths.</blockquote><p>Defining <strong>nested navigation graphs </strong>is the key to handle a complex navigation flow with only on Activity.</p><h4>Defining a navigation graph</h4><p>It may be obvious to some of you on how to define navigation graph of this flow. However, I was not that smart. I used to break the single-activity architecture and put each flow(authentication, flow1, flow2) into different activities. I ended up with the code that wasn’t looked so beautiful. Later on, I came up with a more elegant method which fit the single-activity architecture. I utilized the nested navigation graph. I created the main navigation graph for the main flow and let each sub-flows have their own navigation graph like the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*heiSxI2Rv6f8vJyjDTLYFA.png" /></figure><p>There are totally four navigation graphs. In our one and only Activity, we have <strong>NavHostFragment</strong> set up with <em>@navigation/main_navigation</em> which will be our main graph. Then other three fragments in <em>@navigation/main_navigation</em> will have thier own <strong>NavHostFragment</strong> with different navigation graph set up. Our <em>@navigation/main_navigation</em> graph will look similar to this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80f97817765245083626f6c929cef066/href">https://medium.com/media/80f97817765245083626f6c929cef066/href</a></iframe><p>I will skip the implementation of navigation graph of <em>authenticationFragment</em>, <em>flow1Fragment</em>, and <em>flow2Fragment</em>.</p><h4>Navigating Inside and Between graph</h4><p>Navigating to a destination is done using an element called <strong>NavController</strong>. Each <strong>NavHostFragment </strong>with a navigation graph<strong> </strong>has its own corresponding <strong>NavController</strong> for managing the navigation. For our example, the <strong>NavController</strong> would be attached to Activities or Fragments. I will give them the names like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ZhUkTZRLtheoS1zzWkEuA.png" /></figure><p>As you can see that there’re four <strong>NavController</strong> in our example. <br>At the Activity level, we have <strong>mainNavController</strong> for navigating across each flow. At the fragment level, there are <strong>authenticationNavController</strong>, <strong>flow1NavController</strong>, and <strong>flow2NavController</strong> for controlling the navigation of each specific application flow.</p><p>I’ll bring up another example to explain how we can navigate inside the navigation graph that the screen belong to as well as the way to navigate between different navigation graphs. Suppose we have a login screen that belongs to the authentication navigation graph. It looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*FPtLf0zXMzgFgbb-_p7PyA.png" /></figure><p>This screen should be able to navigate to other authentication-related screens in the same flow such as <strong>ForgotPasswordScreen</strong>, <strong>RegistrationScreen</strong>, and such. However, it should also be able to navigate to the <strong>Flow1</strong> or <strong>Flow2</strong> after the user has successfully logged in. Please see the picture below for visual presentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6xjaCKexcdxB4bVA69gf9A.png" /></figure><p>To make the navigation according to what I’ve mentioned possible, we need to have an instance of both <strong>authenticationNavController</strong> and <strong>mainNavController</strong>, and this is where I see the benefit of using a <strong>Single-Activity architecture.</strong><br>Please see a snippet of <strong>LoginFragment</strong> below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5d0d398a9c46eefcb0a06284cfa0041/href">https://medium.com/media/b5d0d398a9c46eefcb0a06284cfa0041/href</a></iframe><p>As you can see that in <strong>LoginFragment,</strong> we have created <strong>authenticationNavController</strong> and <strong>mainNavController</strong>.<br>- <strong>mainNavController</strong> can be obtained by an instance of the Activity and it used to navigate to fragment outside of the <em>@navigation/authentication_navigation. </em>In this case, it’s to navigate to <em>Flow1Fragment </em>and<em> Flow2Fragment</em><br>- <strong>authenticationNavController</strong> is achieved by an instance of the current view of the Fragment. It helps navigate to the screen inside <em>@navigation/authentication_navigation.</em></p><p>The benefit of using a <strong>Single-Activity Architecture</strong> is that no matter which Fragment you are on or how deep the nested Fragment you are working with. It shares the same activity which means you can always create the instance of <strong>mainNavController</strong> and use it to navigate across the flows.</p><h4>Conclusion</h4><p>By using the concept that I’ve mentioned, it should cover some of the complicate navigation scenarios that we might have faced. <br>Fragments can have access to both the view-level <strong>NavController</strong> and the activity-level <strong>NavController</strong>. In the case of nested Fragment, it doesn’t have to care about what outer-level Fragment navigations are. It only needs to work with its own <strong>NavController</strong>.</p><p>That’s it for this article. Thank you for reading this. If you feel like my approach is not correct or have better implementations, please do suggest in the comment section. I would love to have a discussion. Plus, feel free to leave questions.</p><p>Please feel free to hit the claps and follow me. 😀</p><h4>Want to increase productivity as a developer?</h4><p>Try pomodoro technique with the app Ergo Pomodoro. Please check it out 😀 The app is completely free to use.</p><p>✅ Android: <a href="https://play.google.com/store/apps/details?id=com.nobrain.nobrain_timer">https://play.google.com/store/apps/details...</a><br>✅ iOS: <a href="https://apps.apple.com/us/app/ergonomic-pomodoro-timer/id1550788893?fbclid=IwAR0T9G0kqmZ3orFD0x9NLnfP3fdmhQtMEemcrKCNnK4afu5mA2yCxhTrg5Y">https://apps.apple.com/.../ergonomic.../id1550788893</a></p><h4>Follow me on Github!</h4><p><a href="https://github.com/benBoonya">https://github.com/benBoonya</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ad988602902" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/handle-complex-navigation-flow-with-single-activity-and-android-jetpacks-navigation-component-6ad988602902">Handle Complex Navigation Flow with Single-Activity and Android Jetpack’s Navigation component</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handle Complex Network Call with Kotlin Coroutine + Retrofit 2]]></title>
            <link>https://medium.com/oozou/handle-complex-network-call-with-kotlin-coroutine-retrofit-2-30a6cd1e0189?source=rss-c6b1e8a86f0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/30a6cd1e0189</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[kotlin-coroutines]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Boonya Kitpitak]]></dc:creator>
            <pubDate>Thu, 26 Jul 2018 06:47:19 GMT</pubDate>
            <atom:updated>2018-07-26T09:38:53.622Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qYy_kVJiSKtZ0bH0V4ViJA.jpeg" /><figcaption><a href="https://www.pexels.com/photo/abstract-art-background-brown-279844/">https://www.pexels.com/photo/abstract-art-background-brown-279844/</a></figcaption></figure><p>When you’ve been working with some Android applications, you may encounter the scenario where you have to make multiple network requests such as chained or parallel requests and combine their results.</p><p>To handle the mentioned scenario, some might say “let’s use <strong>RxJava</strong>!!!” but… come on the learning curve of RxJava is no joke, at least for me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*2rEu_x8O05iRSYeBiofztg.jpeg" /></figure><p>Don’t get me wrong, it doesn’t mean that I hate RxJava. RxJava is a really powerful library but <strong>Kotlin coroutine</strong> seem to suit my existing app architecture better.</p><p>In this article, I’ll demonstrate how to use coroutine in order to</p><ul><li>Chain multiple network request</li><li>Create parallel network requests and process the responses when all of them are finished.</li></ul><p>I won’t get into much detail about how coroutine work but I’ll focus on using it in action.</p><h3>Introduction</h3><p>Before we begin I would like to briefly address the concept and the commonly used functions in Coroutine.</p><h4>Brief Concept</h4><p>Writing the code asynchronously has alway been a pain for me, especially when dealing with complex network requests. It’s hard to write easy-to-read code and sometimes you may end up with a lot of callbacks in your code. <strong><em>Therefore, one of the purpose of Kotlin Coroutine is to help us write a neater code when working with asynchronous programming.</em></strong></p><p>Here is what written in Kotlin Official document.</p><blockquote>Coroutines simplify asynchronous programming by putting the complications into libraries. The logic of the program can be expressed <em>sequentially</em> in a coroutine, and the underlying library will figure out the asynchrony for us.</blockquote><h4>Launch and Async</h4><p>launch and async are commonly used functions of coroutine.</p><p>Here are the official definition.</p><blockquote><strong>launch</strong>- Launches new coroutine without blocking current thread and returns a reference to the coroutine as a <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-job/index.html">Job</a>. The coroutine is cancelled when the resulting job is <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-job/cancel.html">cancelled</a>.</blockquote><blockquote><strong>async</strong>- Creates new coroutine and returns its future result as an implementation of <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-deferred/index.html">Deferred</a>. The running coroutine is cancelled when the resulting object is <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-job/cancel.html">cancelled</a>.</blockquote><p>Take a look at this piece of code as an example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94311804d93c6fec57cb589691dfb006/href">https://medium.com/media/94311804d93c6fec57cb589691dfb006/href</a></iframe><p>From the example, the difference between launch and async is that async can return the future result which has a type of Deferred&lt;T&gt; , and we can call await() function to the Deferred variable to get the result of the coroutine while launch only execute the code in the block with out returning the result.</p><h3>Let’s start!</h3><h4>Dependencies</h4><p>Here is the things you need to add to your build.gradle</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32f4d2aa9c189a0a66428ca54c79f727/href">https://medium.com/media/32f4d2aa9c189a0a66428ca54c79f727/href</a></iframe><p>To make Retrofit work seamlessly with Kotlin Coroutine. I used the library called <a href="https://github.com/JakeWharton/retrofit2-kotlin-coroutines-adapter">Kotlin Coroutine Adapter</a> written by Jake Wharton.</p><h4>API Interface</h4><p>Lets create API interface which define the api path we going to deal with.</p><p>Normally, when defining the path in API interface we’ll do something like this right ?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/260e3c6a9a26884c2090623d74504eff/href">https://medium.com/media/260e3c6a9a26884c2090623d74504eff/href</a></iframe><p>However, to make it work with coroutine, we may do it this way.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d32ac6088c65a3679bd1d188a088b67d/href">https://medium.com/media/d32ac6088c65a3679bd1d188a088b67d/href</a></iframe><p>Basically, we made our API interface’s functions return the value as Deferred&lt;T&gt; so that we can use them asynchronously later on.</p><h4>Providing Retrofit API</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4eefdb15d3a3e92813092a4f8e131b03/href">https://medium.com/media/4eefdb15d3a3e92813092a4f8e131b03/href</a></iframe><p>In order to get the value from API interface’s functions as Deferred , we need to specify <strong>Retrofit Call Adapter Factory</strong> this way addCallAdapterFactory(CoroutineCallAdapterFactory())</p><h4>Chaining network requests</h4><p>Let’s say we have to create two network requests in a row and we have to use the result from the first request to create the second one.</p><p>In our example, suppose the path of endpoint path3/{id} depends on the result of the endpoint path1/</p><p>The code may look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d64ff13b08d85b51cd36bbca0fbd9290/href">https://medium.com/media/d64ff13b08d85b51cd36bbca0fbd9290/href</a></iframe><p>To break it down,</p><ul><li>First we call the apiService.getObject1() that returns result which has a type of Deferred&lt;Response&lt;Object1&gt;&gt;</li><li>As I have mention that we could call await() on the Deferred variable to get the result, so we call await() on the apiService.getObject1() so that whenever the result has arrived, it can be used to create another request.</li><li>After we get the result, this code apiService.getObject3(it.id).await() will be called</li><li>And the result will be handle by successHandle like this successHandler(apiService.getObject3(it.id).await())</li></ul><h4>Create parallel network requests</h4><p>Suppose we have to create two requests at the same time then process the results when the responses of both endpoints have returned. In our case, let’s call the endpoint /path1 and /path2 parallelly. The code going to look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0a79dd7630eca69e33cf89f98be9204/href">https://medium.com/media/f0a79dd7630eca69e33cf89f98be9204/href</a></iframe><p>Let’s break it down.</p><ul><li>The requests happen at val getObject1Task = apiService.getObject1() and val getObject2Task = apiService.getObject2(). Although the code is written in the sequential, the requests perform asynchronously.</li><li>Then we pass the results of both requests to be process in successHandler. The results are obtained by getObject1Task.await().body() and getObject2Task.await().body()</li><li>The successHandler will only be called only when both getObject1Task and getObject2Task are finished.</li></ul><h3>Conclusion</h3><p>The above example still doesn’t include the generic way to handle unsuccessful network requests. I may have to take sometime to find the appropriate way to deal that if I want to use the approach in the production app.</p><p>Overall, I’m impressed by how coroutine help us simplify asynchronous programming. Moreover, It gets us out of the callback hell and make it easier to handle complex network requests. I think there is no excuse not to give coroutine a try now.</p><p>If there is any mistake you spot in my article, please let me know. And please suggest on any point that you don’t agree. Thank you very much for reading.</p><h3>Source</h3><ul><li><a href="https://medium.com/@andrea.bresolin/playing-with-kotlin-in-android-coroutines-and-how-to-get-rid-of-the-callback-hell-a96e817c108b">https://medium.com/@andrea.bresolin/playing-with-kotlin-in-android-coroutines-and-how-to-get-rid-of-the-callback-hell-a96e817c108b</a></li><li><a href="https://proandroiddev.com/kotlin-coroutines-handling-concurrency-like-a-pro-retrofit2-coroutines-31cd0611fd91">https://proandroiddev.com/kotlin-coroutines-handling-concurrency-like-a-pro-retrofit2-coroutines-31cd0611fd91</a></li><li>Kotlin for Android Developers book by <a href="https://medium.com/u/a199eb0fa9a0">Antonio Leiva</a>(<a href="https://antonioleiva.com/kotlin-android-developers-book/">https://antonioleiva.com/kotlin-android-developers-book/</a>)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30a6cd1e0189" width="1" height="1" alt=""><hr><p><a href="https://medium.com/oozou/handle-complex-network-call-with-kotlin-coroutine-retrofit-2-30a6cd1e0189">Handle Complex Network Call with Kotlin Coroutine + Retrofit 2</a> was originally published in <a href="https://medium.com/oozou">The OOZOU Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ใครบอกว่า Interface ใส่ Code ไม่ได้ ?]]></title>
            <link>https://medium.com/black-lens/%E0%B9%83%E0%B8%84%E0%B8%A3%E0%B8%9A%E0%B8%AD%E0%B8%81%E0%B8%A7%E0%B9%88%E0%B8%B2-interface-%E0%B9%83%E0%B8%AA%E0%B9%88-code-%E0%B9%84%E0%B8%A1%E0%B9%88%E0%B9%84%E0%B8%94%E0%B9%89-16cf381bca20?source=rss-c6b1e8a86f0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/16cf381bca20</guid>
            <category><![CDATA[kotlin-extension]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[interface-in-kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Boonya Kitpitak]]></dc:creator>
            <pubDate>Thu, 12 Jul 2018 07:33:51 GMT</pubDate>
            <atom:updated>2021-03-02T01:41:16.834Z</atom:updated>
            <content:encoded><![CDATA[<p>ในบทความนี้ผมจะขอพูดถึง Interface ใน Kotlin และสถานการณ์ที่เราควรจะใช้มัน…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*8hKHDrd2CZiPUD8yGOnQFg.jpeg" /></figure><p>หลังจากที่ผมได้คลุกคลีกับเจ้าภาษา Kotlin และใช้มันใน Android Development มาสักพัก ผมเพิ่งได้รู้ว่า Interface ใน Kotlin <br>เนี่ยมันทำอะไรได้มากกว่าใน Java 6 เยอะมากเลยนะ ถ้าเป็นใน Java 6 เนี่ย Interface จะทำหน้าที่ในการกำหนดความสามารถของ Class ที่จะ Implement ตัวมันเฉยๆ แต่ไม่สามารถเขียน Code ที่ทำหน้าที่จริงๆได้</p><p>ต้องขอบคุณ Kotlin ที่ตอนนี้เราสามารถเขียน Code กำหนดหน้าที่การทำงานต่างๆใน Interface ได้ และ Class ที่มา Implement ก็สามารถ Inherit function ไปใช้ได้เลย</p><p>มาดูตัวอย่างกันดีกว่าครับ ถ้าเขียนด้วย Concept ของ Java เราก็คงจะมี Interface หน้าตาประมาณนี้กัน</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae38f5eb423694260484910e88f49332/href">https://medium.com/media/ae38f5eb423694260484910e88f49332/href</a></iframe><p>จากนั้นก็ให้ Class ที่ชื่อว่า Aeroplane กับ Helicopter มา Implement ตัว Interface ที่เราสร้างขึ้นมา</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/480d8020ceea3b3dd3a8ef72d2391768/href">https://medium.com/media/480d8020ceea3b3dd3a8ef72d2391768/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff501e76c9e9213244c25160d73ee37c/href">https://medium.com/media/ff501e76c9e9213244c25160d73ee37c/href</a></iframe><p>ทุกอย่างก็ดูปกติ ไม่ผิดแปลกอะไร แต่อย่างที่ผมบอกไปในตอนแรกว่า เราสามารถเพิ่ม Code ลงไปใน Interface ได้ <br>ดังนั้นเราจะสามารถเพิ่ม Property (ที่จะถูก Overide อีกที) และ Function ลงไปได้ตามนี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6895390bed8048dcf4d52ae87e783e8d/href">https://medium.com/media/6895390bed8048dcf4d52ae87e783e8d/href</a></iframe><p>จากนั้นเราต้องมา Override ตัว Property ที่ชื่อว่า Engine ใน Class Aeroplane กับ Helicopter ด้วย</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da45e59f6c1abc86f6e14bc6bc2fd4ce/href">https://medium.com/media/da45e59f6c1abc86f6e14bc6bc2fd4ce/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32c50c322a4015c6941e72e29453bfe2/href">https://medium.com/media/32c50c322a4015c6941e72e29453bfe2/href</a></iframe><p>หลังจากที่ทุกอย่างเรียบร้อยเราก็สามารถสั่งให้ Aeroplane กับ Helicoptern startEngine ตรงๆ ได้ตามนี้เลย</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c422022d19eb3369797e555f2a6fbc9/href">https://medium.com/media/9c422022d19eb3369797e555f2a6fbc9/href</a></iframe><p>พออ่านมาถึงตรงนี้ท่านผู้อ่านอาจคิดว่ามันก็เจ๋งดีนะ แต่เราจะเอาไปประยุกต์ใช้กับการทำงานจริงของเราได้อย่างไร <br>( แค่ start เครื่องยนต์ของเครื่องบินกับเฮลิคอปเตอร์ดูจะไม่ช่วยอะไรเท่าไหร่ ฮ่าๆๆๆ)</p><p>ผมขอยกตัวอย่างที่ได้ประยุกต์มาจากหนังสือ ชื่อว่า <a href="https://antonioleiva.com/kotlin-android-developers-book/">Kotlin for Android Developer </a>เขียนโดย <a href="https://medium.com/u/a199eb0fa9a0">Antonio Leiva</a> ถ้าใครที่กำลังเริ่มเขียน Kotlin หรือ เขียนมาสักพักแล้วต้องการเสริมพื้นฐานเพิ่มเติม ผมแนะนำให้ลองหามาอ่านกันนะครับ</p><p>เดี๋ยวเราจะมาสร้าง Interface ชื่อว่า SettingToolbarManager ที่ช่วยเราในเรื่องดังต่อไปนี้กันนะครับ</p><ul><li>เปลี่ยน Title ของ Toolbar</li><li>จัดการขณะที่มีการ Click ที่ Setting Menu</li></ul><p>หน้าตาของเจ้าตัว Interface ก็จะประมาณนี้ครับ</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/709c49b1b0c8b5709fbcd0046e4d89f1/href">https://medium.com/media/709c49b1b0c8b5709fbcd0046e4d89f1/href</a></iframe><p>จากนั้นใน MainActivity หรือ Activity อื่นๆที่ต้องการ Setting Menu เราก็ Implement ตัว Interface ที่เราเขียนขึ้นมาแบบนี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d72ff657b1543c194615b23bdfa001e1/href">https://medium.com/media/d72ff657b1543c194615b23bdfa001e1/href</a></iframe><p>ถึงตรงนี้ท่านผู้อ่านน่าจะเห็นถึงประโยชน์ของ Interface บ้างแล้ว ว่ามันสามารถช่วยให้เราแยก Code ที่ต้องเขียนซ้ำซ้อนออกมาจาก Activity Class ได้และมันก็ทำให้หน้าตา Code ของเราดูดีและสะอาดขึ้น อีกทั้ง เรายังสามารถใช้ Interface ที่เราเขียนขึ้นมาใน Class อื่นๆได้อีกด้วย เพื่อที่เราจะได้ไม่เขียน Code เดิมๆซ้ำไปซ้ำมา</p><p>แต่ว่า… Interface ก็ไม่ได้เหมาะสมที่จะใช้ในการ Simplify Codeในทุกกรณีนะ ลองดูตัวอย่างต่อไปนี้กันนะครับ</p><p>เรามาลองสร้าง Interface ที่ช่วยทำให้การสร้าง Toast ของเราง่ายขึ้นกันเถอะ หน้าตาของตัว Interface ก็จะเป็นแบบนี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a338e935a83cc8281da1a902ea8fca7/href">https://medium.com/media/1a338e935a83cc8281da1a902ea8fca7/href</a></iframe><p>จากนั้นเราก็ให้ Activity มา Implement ตัว Interface ด้านบน เราก็จะได้ Class ที่เป็นแบบนี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/580e7e0a333cb112acf132a0cb4817c0/href">https://medium.com/media/580e7e0a333cb112acf132a0cb4817c0/href</a></iframe><p>ทุกอย่างก็ปกติดี เจ้าตัว ToastManager ก็ทำหน้าที่ของมันได้ครบถ้วนสมบูรณ์</p><p>เพียงแต่ว่า…</p><p>ในกรณีนี้เรามีวิธีการที่ดีกว่า โดยเราสามารถใช้ Kotlin Extension ได้!!</p><p>แทนที่จะสร้าง Interface ขึ้นมาเราสามารถเขียน Extension Function ขึ้นมาแทนแบบนี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f95ad632e9f1c0e88dffceb540a9d1db/href">https://medium.com/media/f95ad632e9f1c0e88dffceb540a9d1db/href</a></iframe><p>ทีนี้ Activity ของเราก็สามารถเรียกใช้ Toastได้ตามนี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2d108ba97334ddfec2ab4771a3b06ea/href">https://medium.com/media/e2d108ba97334ddfec2ab4771a3b06ea/href</a></iframe><p>อย่างที่เห็นกันว่า เราไม่ต้องไป Implement Interface และ Override Context เลย และเราก็สามารถเข้าถึง Function longToastได้เลย นั่นก็เพราะว่า ToastActivity ของพวกเรา extend AppCompatActivity ซึ่ง มันเป็น Instance หนึ่งของ Activity</p><h3>สรุป และ ความคิดเห็นส่วนตัว</h3><p>ว่ากันด้วยเรื่อง <strong>Interface VS</strong> <strong>Extension</strong></p><p>ทั้ง Interface และ Extension สามารถช่วยให้เราลดการเขียน Code ที่ไม่จำเป็นออกไปได้จำนวนมาก แต่มันจะใช้งานในสถานการณ์ที่ต่างกัน</p><p>โดยส่วนตัวผมคิดว่า</p><ul><li>เราควรใช้ <strong>Interface</strong> ในกรณีที่เราต้องการ Behavior ที่ค่อนข้างจะเฉพาะเจาะจงกับ Class กลุ่มหนึ่ง เช่น เราต้องการสร้าง Activity ที่มี setting menu แบบที่ผมยกตัวอย่างให้ดูในข้างต้น</li><li><strong>Extension Function </strong>ควรถูกนำมาใช้ เมื่อ Behavior ที่เราต้องการนั้นเหมือนกันในทุกๆ Instance ของ Class เช่น เราต้องการให้ทุก Activity สามารถสร้าง Toast ได้แบบง่ายๆดังตัวอย่างด้านบน</li></ul><p>อย่างไรก็ตามที่อธิบายมานี้เป็นความเห็นส่วนตัวของผมนะครับ ท่านผู้อ่านมีความคิดเห็นเหมือนหรือต่างอย่างไรลองมาแชร์กันนะครับ :)</p><p>ขอบคุณท่านผู้อ่านทุกท่านครับ</p><p>ฝากติดตาม Page Facebook เพื่อรับข่าวสารเพิ่มเติมกัน ตามลิงค์นี้<br><a href="https://www.facebook.com/codewithoutbrain/">https://www.facebook.com/codewithoutbrain/</a></p><h3>ที่มา</h3><ul><li><a href="https://medium.com/@rameshprasad/supercharged-interfaces-in-kotlin-53c506c53612">https://medium.com/@rameshprasad/supercharged-interfaces-in-kotlin-53c506c53612</a></li><li>Kotlin for Android Developers book by <a href="https://medium.com/u/a199eb0fa9a0">Antonio Leiva</a> (<a href="https://antonioleiva.com/kotlin-android-developers-book/">https://antonioleiva.com/kotlin-android-developers-book/</a>)</li><li><a href="https://antonioleiva.com/interfaces-kotlin/">https://antonioleiva.com/interfaces-kotlin/</a></li></ul><p><strong>💁‍♂️ อยากเพิ่ม Productivity ในการทำงานรึเปล่า?<br> <br></strong>ลองใช้แอป Ergo Pomodoro ที่พัฒนาโดย page ของกันกันเถอะ แอปนี้ใช้การจับเวลาแบบ Pomodoro เพื่อเพิ่มประสิทธิภาพการทำงานให้ดียิ่งขึ้น ใช้งานฟรีดาวน์โหลดได้เลย!</p><p>✅ Android: <a href="http://bit.ly/3pZOuEE">bit.ly<strong>/3pZOuEE</strong></a><strong><br></strong>✅ iOS: <a href="https://apps.apple.com/us/app/ergonomic-pomodoro-timer/id1550788893">https://apps.apple.com/us/app/ergonomic-pomodoro-timer/id1550788893</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16cf381bca20" width="1" height="1" alt=""><hr><p><a href="https://medium.com/black-lens/%E0%B9%83%E0%B8%84%E0%B8%A3%E0%B8%9A%E0%B8%AD%E0%B8%81%E0%B8%A7%E0%B9%88%E0%B8%B2-interface-%E0%B9%83%E0%B8%AA%E0%B9%88-code-%E0%B9%84%E0%B8%A1%E0%B9%88%E0%B9%84%E0%B8%94%E0%B9%89-16cf381bca20">ใครบอกว่า Interface ใส่ Code ไม่ได้ ?</a> was originally published in <a href="https://medium.com/black-lens">Black Lens</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interface in Kotlin and when to use it]]></title>
            <link>https://medium.com/oozou/interface-in-kotlin-and-when-to-use-it-5d32caab19be?source=rss-c6b1e8a86f0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d32caab19be</guid>
            <category><![CDATA[interface-in-kotlin]]></category>
            <category><![CDATA[android-apps]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Boonya Kitpitak]]></dc:creator>
            <pubDate>Thu, 05 Jul 2018 14:46:56 GMT</pubDate>
            <atom:updated>2018-07-12T07:29:11.610Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*PG7q_78CFDUWF4Q8z247Lw.png" /></figure><p>After using Kotlin in Android development for a while, I’ve just realized the benefit of <strong>Interface in Kotlin. </strong>In Java 6,<strong> </strong>Interface<strong> </strong>can only be used to describe the behaviors, but not implement them.</p><p>Fortunately, Kotlin allows Interface to have code which means a class can implement an Interface, and inherit the behavior from it.</p><p>To begin with, if you come from Java, you might have an interface like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae38f5eb423694260484910e88f49332/href">https://medium.com/media/ae38f5eb423694260484910e88f49332/href</a></iframe><p>Let’s have Aeroplane and Helicopter implement the Interface like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/480d8020ceea3b3dd3a8ef72d2391768/href">https://medium.com/media/480d8020ceea3b3dd3a8ef72d2391768/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75b74db9a133cc9608dce36371a73a26/href">https://medium.com/media/75b74db9a133cc9608dce36371a73a26/href</a></iframe><p>Nothing wrong with them right ? However, as Kotlin allows us to have code in the Interface, we can define a property to be overridden and implement funtion in the Interface like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6895390bed8048dcf4d52ae87e783e8d/href">https://medium.com/media/6895390bed8048dcf4d52ae87e783e8d/href</a></iframe><p>Then we just have to override the property in our classes as the followings.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da45e59f6c1abc86f6e14bc6bc2fd4ce/href">https://medium.com/media/da45e59f6c1abc86f6e14bc6bc2fd4ce/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32c50c322a4015c6941e72e29453bfe2/href">https://medium.com/media/32c50c322a4015c6941e72e29453bfe2/href</a></iframe><p>When we want to start engine of our Aeroplane or Helicopter, we can directly call the function like this!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c422022d19eb3369797e555f2a6fbc9/href">https://medium.com/media/9c422022d19eb3369797e555f2a6fbc9/href</a></iframe><p>You may wonder how could we use this in action (more than just start the engine of aeroplane and helicopter)</p><p>I’ll take the example derived from part of the book called <a href="https://antonioleiva.com/kotlin-android-developers-book/">Kotlin for Android Developer</a> by Antonio Leiva. It’s really good book for every Android Developer who want to start using Kotlin.</p><p>Basically, we are going to create an interface that help us</p><ul><li>Set the toolbar title</li><li>Handle the click on setting menu</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/709c49b1b0c8b5709fbcd0046e4d89f1/href">https://medium.com/media/709c49b1b0c8b5709fbcd0046e4d89f1/href</a></iframe><p>Then in your MainActivity or other activities that need setting menu, we can make them implement our interface.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d72ff657b1543c194615b23bdfa001e1/href">https://medium.com/media/d72ff657b1543c194615b23bdfa001e1/href</a></iframe><p>As you can see that the interface helps us separate some common code from activities and it makes you code look a bit cleaner. Moreover, we can reuse our interface in multiple places so that we don’t need to write the same code over and over again.</p><p>However, interface is not always a suitable solution to simplify our code. Let’s look at the next example.</p><p>Let’s create the interface that help us simplify the process of creating Toast</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a338e935a83cc8281da1a902ea8fca7/href">https://medium.com/media/1a338e935a83cc8281da1a902ea8fca7/href</a></iframe><p>An activity that implement the interface might look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/580e7e0a333cb112acf132a0cb4817c0/href">https://medium.com/media/580e7e0a333cb112acf132a0cb4817c0/href</a></iframe><p>Everything seem to be fine with the above example. The ToastManager is doing its job well ,but in this case we have an easier solution. We can use <strong>Kotlin Extension!!</strong></p><p>Instead of create the interface like what we have done, we could write extensions functions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f95ad632e9f1c0e88dffceb540a9d1db/href">https://medium.com/media/f95ad632e9f1c0e88dffceb540a9d1db/href</a></iframe><p>As you can see in the example below that without implementing interface and overriding context , we can access the functions longToast because our ToastActivity has extended AppCompatActivity which consider to be Activity instance.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2d108ba97334ddfec2ab4771a3b06ea/href">https://medium.com/media/e2d108ba97334ddfec2ab4771a3b06ea/href</a></iframe><h3>Discussion &amp; Conclusion</h3><p><strong>Interface </strong>vs<strong> Extension</strong></p><p>In my opinion, if the functionality you want to achieve is common to every instance of the particular Class, using <strong>Extension</strong> is a way to go. However, when you want a behavior that is more specific, <strong>Interface</strong> is consider to be more appropriate like SettingToolbarManager in the above example.</p><p>This is just my own thought. Please suggest if you don’t agree. :)</p><p>Anyway <strong>Interface</strong> is a great way to simplify your code and avoid repeating yourself.</p><h3>Source</h3><ul><li><a href="https://medium.com/@rameshprasad/supercharged-interfaces-in-kotlin-53c506c53612">https://medium.com/@rameshprasad/supercharged-interfaces-in-kotlin-53c506c53612</a></li><li>Kotlin for Android Developers book by <a href="https://medium.com/u/a199eb0fa9a0">Antonio Leiva</a> (<a href="https://antonioleiva.com/kotlin-android-developers-book/">https://antonioleiva.com/kotlin-android-developers-book/</a>)</li><li><a href="https://antonioleiva.com/interfaces-kotlin/">https://antonioleiva.com/interfaces-kotlin/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d32caab19be" width="1" height="1" alt=""><hr><p><a href="https://medium.com/oozou/interface-in-kotlin-and-when-to-use-it-5d32caab19be">Interface in Kotlin and when to use it</a> was originally published in <a href="https://medium.com/oozou">The OOZOU Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>