<?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 Danielius Ašmontas on Medium]]></title>
        <description><![CDATA[Stories by Danielius Ašmontas on Medium]]></description>
        <link>https://medium.com/@dasmontas?source=rss-1dcbf06c42de------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Ct-aqI-Tg1kQPJKLtfiozg.jpeg</url>
            <title>Stories by Danielius Ašmontas on Medium</title>
            <link>https://medium.com/@dasmontas?source=rss-1dcbf06c42de------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 05:38:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dasmontas/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[Using Butter Knife to bind views and more]]></title>
            <link>https://medium.com/@dasmontas/using-butter-knife-to-bind-views-and-more-dc3710d61581?source=rss-1dcbf06c42de------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc3710d61581</guid>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Danielius Ašmontas]]></dc:creator>
            <pubDate>Fri, 19 May 2017 22:53:09 GMT</pubDate>
            <atom:updated>2017-05-19T22:54:35.931Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/293/0*2JXy60oqx6ffPGQc.png" /></figure><p><a href="http://jakewharton.github.io/butterknife/"><strong>Butter Knife</strong></a> is an Android view injection library that reduces unnecessary code. This library was developed by <a href="https://medium.com/u/8ddd94878165">Jake Wharton</a>. It helps you to:</p><ul><li>Bind single and multiple views</li><li>Bind resources</li><li>Bind listeners</li></ul><p>To start using <strong>Butter Knife</strong> in your Android application all you have to do is add these 2 lines inside your <em>build.gradle</em> file and sync your project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/011250dfc14593dde1f0d34517341016/href">https://medium.com/media/011250dfc14593dde1f0d34517341016/href</a></iframe><p>Now that that’s over and done with let’s see what we can do with <strong>Butter Knife</strong>. We are going to build a simple app now to showcase this cool library. Lets use 3 <strong>TextViews</strong> and a<strong> Button</strong> inside our <em>activity_main.xml</em> layout:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecd83bc0d1335d51b0b0b44a0518a055/href">https://medium.com/media/ecd83bc0d1335d51b0b0b44a0518a055/href</a></iframe><h3>Binding single Views</h3><p>Normally, what we do to access a <strong>View</strong> from our activity is to use <em>findViewById(int resourceId). </em>Gladly, <strong>Butter Knife</strong> does this for us so we no longer need to worry about forgetting to initialize our views:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9f057fe36012b56fa16dbecf9d2d44e/href">https://medium.com/media/d9f057fe36012b56fa16dbecf9d2d44e/href</a></iframe><p>All we need to write is an annotation <em>BindView(int resourceId) </em>and <strong>Butter Knife</strong> will inject the view for us. Also, notice we have a line <em>ButterKnife.bind(this) </em>in our<em> onCreate() </em>method which is necessary in order for this to work.</p><h3>Binding multiple fields</h3><p>To bind multiple fields at once we use <em>BindViews</em> annotation. We also create a <strong>List </strong>of textviews to store multiple <strong>TextView</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da60fb2f671c8877672831ac51e50a0a/href">https://medium.com/media/da60fb2f671c8877672831ac51e50a0a/href</a></iframe><p>Hmm, the text seems to be too small and I want to increase it without repeating myself 2 times. In <strong>onCreate</strong> we call:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fcfdaa25d1501afb809d33f7755aeb79/href">https://medium.com/media/fcfdaa25d1501afb809d33f7755aeb79/href</a></iframe><p>Where SIZE is a <strong>ButterKnife.Setter </strong>field. We override <em>set()</em> method so that we can change each <strong>TextView</strong> text size:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8da7d0dc7bdd802ef9a4bd6e6465a23d/href">https://medium.com/media/8da7d0dc7bdd802ef9a4bd6e6465a23d/href</a></iframe><h3>Binding onClick listeners</h3><p>Remember that button from our <em>activity_main.xml</em> ? How about we use <strong>Butter Knife</strong> to register clicks and show how many times the button was clicked. For this we use <em>OnClick(int resourceId) </em>annotation to bind our method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9aba44795879f1fc2ca5ae046031034a/href">https://medium.com/media/9aba44795879f1fc2ca5ae046031034a/href</a></iframe><p>Simple as that! No need to use any <em>setOnClickListener() </em>and also notice that our <em>OnCreate</em> has a lot less lines of code. Heres the full <strong>MainActivity</strong> class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20fe9e28d7aedfd654233175f65cd1d0/href">https://medium.com/media/20fe9e28d7aedfd654233175f65cd1d0/href</a></iframe><p>And here’s our final result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*zwQUz3N-g80gKe8YuaAX3w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc3710d61581" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Activities and how do you start them ?]]></title>
            <link>https://medium.com/@dasmontas/android-activities-and-how-do-you-start-them-dec8d7987a92?source=rss-1dcbf06c42de------2</link>
            <guid isPermaLink="false">https://medium.com/p/dec8d7987a92</guid>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Danielius Ašmontas]]></dc:creator>
            <pubDate>Thu, 18 May 2017 22:57:51 GMT</pubDate>
            <atom:updated>2017-05-18T22:57:51.156Z</atom:updated>
            <content:encoded><![CDATA[<p>In this guide we will be looking into Android activity lifecycle and learning to use intents to start activities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/0*mEAffws1yqwBMaeK.png" /><figcaption>Activity lifecycle</figcaption></figure><p>If you havent read my previous post be sure to <a href="https://medium.com/@visio_gen/building-our-first-android-app-432fdca899fc">check it out</a>. In it I wrote:</p><blockquote>Usually, the whole Android app consists of lots of activities and each of them have different goals to accomplish. In our app, we can have one activity to use as a login screen and another activity to play music in.</blockquote><p>When looking at the activity lyfecycle we can see that a method gets called depending on which state the Activity is in. Lets look at these methods one by one and try to understand how they work:</p><ul><li><strong><em>onCreate() </em></strong>activity starts by calling this method. Here we initialize and set up our views.</li><li><strong><em>onStart() </em></strong>called when the activity is visible to the user.</li><li><strong><em>onResume() </em></strong>called when the activity starts functioning and interacting with the user. This is where you should resume your animations.</li><li><strong><em>onPause() </em></strong>when a new activity gets started the previous one will be put to background and paused. It is recommended to save activity instance state here.</li><li><strong><em>onStop() </em></strong>called when an activity is no longer in the foreground followed by onRestart() or onDestroy().</li><li><strong><em>onRestart() </em></strong>When a user goes back to previous activity that activity gets restarted and then onStart() gets called afterwards.</li><li><strong><em>onDestroy() </em></strong>this method gets called either when somebody calls finish() or the system is running out of memory and needs to allocate by destroying the activity.</li></ul><h3><strong>Starting a new Activity</strong></h3><p>Before you want to start a new activity, make sure to create one on Android Studio like in the picture below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*IabNCLb9yzEILfrEgMHCUg.png" /></figure><p>That way Android Studio will also create a layout file for your activity and add the activity to android manifest so you don’t have to worry about it. There’s two ways to start an Activity:</p><ul><li><strong><em>startActivity(Intent)</em></strong></li><li><strong><em>startActivityForResult(Intent, int)</em></strong></li></ul><p>Lets do something more challenging. Lets start our <strong>SecondActivity</strong> and pass some data to it and display it as text. Lets start by opening up our layout file <em>activity_second.xml</em> and adding in a TextView:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f2f5ee247f40a39afd266d74d817e08/href">https://medium.com/media/6f2f5ee247f40a39afd266d74d817e08/href</a></iframe><p>In our first activity <strong>MainActivity</strong> we create a new Intent object by providing it the current activity (this) and the activity that we want to start that is <strong>SecondActivity</strong>. We also call <em>putExtra(String name, String value)</em> to pass in some data to our next activity:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1987cb28a318b9677c4fd439ac2a2fc6/href">https://medium.com/media/1987cb28a318b9677c4fd439ac2a2fc6/href</a></iframe><p>In our <strong>SecondActivity</strong> all we have to do is to get the intent, <strong>TextView</strong> and set its text:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51934f51c8d28597df6f7c944c3e4711/href">https://medium.com/media/51934f51c8d28597df6f7c944c3e4711/href</a></iframe><h3>Starting activity with a result</h3><p>When starting activity for a result in your <strong>MainActivity</strong> you will need to override <em>onActivityResult</em> method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09a75b77010b6a827b1f1c76d22a8cd0/href">https://medium.com/media/09a75b77010b6a827b1f1c76d22a8cd0/href</a></iframe><p>Once you start <strong>SecondActivity</strong>, to return the result all you need to do is call <em>setResult(int, Intent) :</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/923aa421533eba3a9221c263f18ea3ad/href">https://medium.com/media/923aa421533eba3a9221c263f18ea3ad/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dec8d7987a92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building our first Android app: basics]]></title>
            <link>https://medium.com/@dasmontas/building-our-first-android-app-432fdca899fc?source=rss-1dcbf06c42de------2</link>
            <guid isPermaLink="false">https://medium.com/p/432fdca899fc</guid>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Danielius Ašmontas]]></dc:creator>
            <pubDate>Wed, 17 May 2017 20:07:33 GMT</pubDate>
            <atom:updated>2017-05-17T21:21:48.889Z</atom:updated>
            <content:encoded><![CDATA[<p>Instead of this being another boring post about writing your first hello world app I think it would be better to develop an actual application that we can use. I feel like the best way to learn is by being practical. The more apps we develop the better we get. We will be going through step by step trying to figure out how things work. As a first project let’s just build a music player app by using Soundcloud API.</p><p>In this series I will be using Android Studio IDE and my android phone to test the apps. You can either connect your own phone through USB to your computer or use a virtual device. I will write a guide about this later. If you are having any problems with installing Android Studio feel free to ask me I will gladly help.</p><h3>Creating A New Project</h3><p>Open up Android Studio and start a new project. Name it whatever you feel like and make sure you select Empty Activity like in the picture below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UyWZjVfejICO3yWPhk8a_Q.png" /></figure><p>Once Android Studio finishes loading up you will see a MainActivity.java or whatever else you named it.</p><h3>Activities</h3><p>Imagine our whole Android app is like a book. In that book a single page would be like an activity. A page can have text and pictures in it. Activity holds UI that users can interact with and it provides basic functionality.</p><p>Usually, the whole Android app consists of lots of activities and each of them have different goals to accomplish. In our music player app, we can have one activity to use as a login screen and another activity to play music in.</p><p>As you create a new project in your <strong>MainActivity</strong> class you will see <em>onCreate</em> method. Activities have many other methods that we could use but for now lets just know that we use <em>onCreate</em> to initialize our activity because it’s the first thing that gets called when we start a new activity. With <em>setContentView</em> we set our UI by defining our layout resource file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b05204d691227f1a73c0cd24603da317/href">https://medium.com/media/b05204d691227f1a73c0cd24603da317/href</a></iframe><p>I will write a more detailed guide on Activities later.</p><h3>Layouts</h3><p>Layouts are where we create our user interface. Where in web development you would use <strong>HTML</strong>, here you use <strong>XML</strong> to declare elements. Heres an example of <em>activity_main.xml </em>layout:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/654f00fe800670c7805fa46386040cd6/href">https://medium.com/media/654f00fe800670c7805fa46386040cd6/href</a></iframe><p>If we would run our app we would see a Hello world text. There’s many more UI elements like <em>EditText</em>, <em>Button</em> and other.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=432fdca899fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android development blog: Preface]]></title>
            <link>https://medium.com/@dasmontas/android-development-blog-preface-714d345dd974?source=rss-1dcbf06c42de------2</link>
            <guid isPermaLink="false">https://medium.com/p/714d345dd974</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Danielius Ašmontas]]></dc:creator>
            <pubDate>Tue, 16 May 2017 20:37:08 GMT</pubDate>
            <atom:updated>2017-05-16T20:40:13.179Z</atom:updated>
            <content:encoded><![CDATA[<p>Before we begin diving deep into Android programming I feel like I need to introduce myself first and what my plans are for the upcoming journey to mastering Android.</p><h3>About Me</h3><p>I`m Danielius Ašmontas 21 years old from Lithuania. I have been programming on and off for a while now. I have some knowledge of Java, Android, Unity3D, Laravel, AngularJS and other. My problem is that I like all of the previously mentioned programming languages/frameworks that to simply put it are: Game, Mobile App, and Web development. Honestly, it would be pretty hard to be skilled in all of them. I just feel like Android is the place where I belong, that I need to settle and focus 100% of my time on it. At least for now.</p><h3>Why Blog?</h3><p>Why not ? I feel like documenting my goal of getting experienced in Android is the right thing to do and also give back by maybe helping a few people out there like me struggling to learn to develop Android apps. Surely, I might not be the best when it comes to writing but bear with me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=714d345dd974" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>