<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kotlin &amp; Java Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/category/software-engineering/kotlin/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/category/software-engineering/kotlin/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Wed, 17 Dec 2025 10:07:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>How to get the current working directory in Kotlin</title>
		<link>https://creatronix.de/how-to-get-the-current-working-directory-in-kotlin/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Fri, 06 May 2022 06:24:55 +0000</pubDate>
				<category><![CDATA[Kotlin & Java]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=5524</guid>

					<description><![CDATA[<p>Sometimes it&#8217;s nice to know where you are. import java.nio.file.Paths fun main() { val cwd = Paths.get("").toAbsolutePath() println(cwd.toString()) }</p>
<p>The post <a href="https://creatronix.de/how-to-get-the-current-working-directory-in-kotlin/">How to get the current working directory in Kotlin</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Sometimes it&#8217;s nice to know where you are.</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-kotlin" data-lang="Kotlin"><code>import java.nio.file.Paths

fun main() {
    val cwd = Paths.get("").toAbsolutePath()
    println(cwd.toString())
}</code></pre>
</div>
<p>The post <a href="https://creatronix.de/how-to-get-the-current-working-directory-in-kotlin/">How to get the current working directory in Kotlin</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Reading files with Kotlin</title>
		<link>https://creatronix.de/reading-files-with-kotlin/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Thu, 05 May 2022 06:26:15 +0000</pubDate>
				<category><![CDATA[Kotlin & Java]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=5514</guid>

					<description><![CDATA[<p>Before Kotlin BufferedReader br = new BufferedReader(new FileReader("data.txt")); try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } String content = sb.toString(); } finally { br.close(); } This is a code sample reading a files content in plain old Java. What a mess&#8230;</p>
<p>The post <a href="https://creatronix.de/reading-files-with-kotlin/">Reading files with Kotlin</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Before Kotlin</h2>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Java"><code>BufferedReader br = new BufferedReader(new FileReader("data.txt")); 

try { 
    StringBuilder sb = new StringBuilder();
    String line = br.readLine(); 
    
    while (line != null) { 
        sb.append(line); 
        sb.append(System.lineSeparator());
        line = br.readLine(); 
    } 
   
    String content = sb.toString(); 
} finally { 
    br.close(); 
}</code></pre>
</div>
<p>This is a code sample reading a files content in plain old Java. What a mess 🙂</p>
<h2>With Kotlin</h2>
<p>Look at this beauty!</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-kotlin" data-lang="Kotlin"><code>val file = File("./data.txt") 
val contents = file.readText() 
val lines = contents.lines() 

lines.forEach { println(it) }</code></pre>
</div>
<p>Yes there is Apache commons IO and yes since java 7 things have been easier as well, but with Kotlin I feel like I can concentrate on solving problems and not trying to don&#8217;t do things wrong 🙂</p>
<h2>Further Reading</h2>
<p><a href="https://stackoverflow.com/questions/4716503/reading-a-plain-text-file-in-java">https://stackoverflow.com/questions/4716503/reading-a-plain-text-file-in-java</a></p>
<p><a href="https://creatronix.de/kotlin-tutorial/">Kotlin Tutorial</a></p>
<p>The post <a href="https://creatronix.de/reading-files-with-kotlin/">Reading files with Kotlin</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to write unit tests in Kotlin</title>
		<link>https://creatronix.de/how-to-write-unit-tests-in-kotlin/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Mon, 25 Apr 2022 14:20:10 +0000</pubDate>
				<category><![CDATA[Kotlin & Java]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=5480</guid>

					<description><![CDATA[<p>Dependency First you need to add the following dependency to your build.gradle file dependencies { testImplementation 'org.jetbrains.kotlin:kotlin-test' As a second step you need to add the task test { useJUnitPlatform() } Implementation When you are familiar with JUnit you may recognized the @Test annotation. Assertions work pretty much the same. You can choose from a&#8230;</p>
<p>The post <a href="https://creatronix.de/how-to-write-unit-tests-in-kotlin/">How to write unit tests in Kotlin</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Dependency</h2>
<p>First you need to add the following dependency to your build.gradle file</p>
<pre>dependencies {

    testImplementation 'org.jetbrains.kotlin:kotlin-test'


</pre>
<p>As a second step you need to add the task</p>
<pre>test {
    useJUnitPlatform()
}

</pre>
<h2>Implementation</h2>
<p>When you are familiar with JUnit you may recognized the @Test annotation.</p>
<p>Assertions work pretty much the same. You can choose from a variety of assert functions.</p>
<pre>import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

</pre>
<pre>internal class TestCC06 {

    <strong>@Test</strong>
    fun testPasswordLength() {
        val myPassword: String = generatePassword()
        <strong>assertEquals</strong>(8, myPassword.length)
    }
    @Test
    fun testPasswordHasDigit() {
        val myPassword: String = generatePassword()
        var hasDigit = false
        println(myPassword)
        for (c in myPassword){
            if(c.isDigit()){
                hasDigit = true
            }
        }
        <strong>assertTrue</strong>(hasDigit)
    }</pre>
<p>The post <a href="https://creatronix.de/how-to-write-unit-tests-in-kotlin/">How to write unit tests in Kotlin</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Kotlin Tutorial</title>
		<link>https://creatronix.de/kotlin-tutorial/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Sat, 26 Mar 2022 08:47:25 +0000</pubDate>
				<category><![CDATA[Kotlin & Java]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=5335</guid>

					<description><![CDATA[<p>This is the overview page for my little Kotlin tutorial Learning Kotlin Part 1 &#8211; print Learning Kotlin Part 2 &#8211; arrays Learning Kotlin Part 3 &#8211; ranges Learning Kotlin Part 4 &#8211; conditionals Learning Kotlin Part 5 &#8211; loops Learning Kotlin Part 6 &#8211; functions Learning Kotlin Part 7 &#8211; multiple return values Reading&#8230;</p>
<p>The post <a href="https://creatronix.de/kotlin-tutorial/">Kotlin Tutorial</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This is the overview page for my little Kotlin tutorial</p>
<p><a href="https://creatronix.de/learning-kotlin-part-1/">Learning Kotlin Part 1 &#8211; print</a></p>
<p><a href="https://creatronix.de/learning-kotlin-part-2/">Learning Kotlin Part 2 &#8211; arrays</a></p>
<p><a href="https://creatronix.de/learning-kotlin-part-3/">Learning Kotlin Part 3 &#8211; ranges</a></p>
<p><a href="https://creatronix.de/learning-kotlin-part-4/">Learning Kotlin Part 4 &#8211; conditionals</a></p>
<p><a href="https://creatronix.de/learning-kotlin-part-5/">Learning Kotlin Part 5 &#8211; loops</a></p>
<p><a href="https://creatronix.de/learning-kotlin-part-6/">Learning Kotlin Part 6 &#8211; functions</a></p>
<p><a href="https://creatronix.de/learning-kotlin-part-7/">Learning Kotlin Part 7 &#8211; multiple return values</a></p>
<p><a href="https://creatronix.de/reading-files-with-kotlin/">Reading files with Kotlin</a></p>
<p><a href="https://creatronix.de/how-to-get-the-current-working-directory-in-kotlin/">How to get the current working directory in Kotlin</a></p>
<p><a href="https://creatronix.de/classes-in-kotlin/">Classes in Kotlin Part 1</a></p>
<p><a href="https://creatronix.de/classes-in-kotlin-part-2/">Classes in Kotlin Part 2</a></p>
<p><a href="https://creatronix.de/how-to-create-a-mutable-list-in-kotlin/">How to create a mutable list in Kotlin?</a></p>
<p><a href="https://creatronix.de/log4j2-for-kotlin/">Log4j2 for Kotlin</a></p>
<p><a href="https://creatronix.de/kotlinx-datetime/">Kotlinx Datetime</a></p>
<p><a href="https://creatronix.de/how-to-write-unit-tests-in-kotlin/">How to write unit tests in Kotlin</a></p>
<p>&nbsp;</p>
<p>The post <a href="https://creatronix.de/kotlin-tutorial/">Kotlin Tutorial</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Dependency Injection with Koin and Kotlin in Android</title>
		<link>https://creatronix.de/dependency-injection-with-koin-and-kotlin-in-android/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Sun, 16 Jan 2022 13:31:53 +0000</pubDate>
				<category><![CDATA[Android & iOS development]]></category>
		<category><![CDATA[Kotlin & Java]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=4528</guid>

					<description><![CDATA[<p>This article is a guest post from Caroline Riekert Motivation There are a lot of reasons to use Dependency Injection, or even a Framework for it. In this Article you&#8217;ll learn what Dependency Injection is, what benefits and downsides it has and how to use it with the usage of the Koin Framework. Let&#8217;s look&#8230;</p>
<p>The post <a href="https://creatronix.de/dependency-injection-with-koin-and-kotlin-in-android/">Dependency Injection with Koin and Kotlin in Android</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This article is a guest post from <a href="https://twitter.com/mahoca6">Caroline Riekert</a></p>
<h2>Motivation</h2>
<p>There are a lot of reasons to use Dependency Injection, or even a Framework for it.</p>
<p>In this Article you&#8217;ll learn what Dependency Injection is, what benefits and downsides it has and how to use it with the usage of the Koin Framework.</p>
<p>Let&#8217;s look at a example of a House with a Doorbell to better understand what dependency injection is.</p>
<p>The House class has a function that returns a String representing the current Ringtone according to the installed doorbell.</p>
<p>Without Dependency Injection:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>class House() {
    private val myDoorbell: Doorbell
   
   init {
       myDoorbell = SpeakingDoorbell()
   }
   
   fun ringDoorbell(): String {
       return "Current ringtone " + myDoorbell.getRingtone()
   }
}

fun main() {
    val myHouse = House()
   
    println(myHouse.ringDoorbell())
}
</code></pre>
</div>
<p>With Dependency Injection:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>class House(private val myDoorbell: Doorbell) {
   fun ringDoorbell(): String {
       return "Current ringtone " + myDoorbell.getRingtone()
   }
}

fun main() {
    val myDoorbell: Doorbell = SpeakingDoorbell()
    val myHouse = House(myDoorbell)
   
    println(myHouse.ringDoorbell())
}</code></pre>
</div>
<p>As you can see in the variant without Dependency Injection the House class has a direct dependency to the SpeakingDoorbell class.</p>
<p>With Dependency Injection this reference no longer exists. The only reference<br />
remaining is to the generalized Doorbell Interface.</p>
<h2>Benefits of Dependency Injection</h2>
<h3>Flexibility</h3>
<p>Lets suppose another class FunnyDoorbell should be used in the future, which also implements the <strong>Doorbell</strong> interface.</p>
<p>Exchanging the SpeakingDoorbell class later on is less work with Dependency Injection.</p>
<p>In the first example the House class would have to change its implementation to switch to the FunnyDoorbell class.</p>
<p>But with Dependency Injection this change can be done without touching the House class.</p>
<p>In fact the House class does not even know whether it got an instance of SpeakingDoorbell or FunnyDoorbell.</p>
<p>This allows to write more flexible code which can be modified and extended easier.</p>
<p>A looser coupling between classes is achieved.</p>
<h3>Testability</h3>
<p>When writing tests one cannot test the House class in the first example in isolation to the SpeakingDoorbell class.</p>
<p>With Dependency Injection it&#8217;s very easy to insert mocks instead of the real instance.</p>
<h2>Downsides of Dependency Injection</h2>
<p>There is one part that got more complex though. The main function now knows not only the House class, but also the SpeakingDoorbell class.</p>
<p>This ultimately leads to a really big main function, that knows almost every component.</p>
<p>In this small example this is no issue, but when developing large applications we want the benefits of Dependency Injection, but as few downsides as possible.</p>
<p>This is exactly where Dependency Injection Frameworks comes into play!</p>
<p>They help to structure the whole block how and when to instantiate which classes and usually bring with them a bunch of useful features.</p>
<p>So let us look into the Dependency Injection Framework Koin.</p>
<h2>Setting up Koin</h2>
<h3>Gradle</h3>
<p>Add the following to your gradle configuration.<br />
Get the latest Koin version [here](https://insert-koin.io/docs/setup/v3).</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Gradle"><code>// Add Maven Central to your repositories if needed
repositories {
    mavenCentral()    
}
dependencies {
    // Koin for Android
    implementation "io.insert-koin:koin-android:$koin_version"
}</code></pre>
</div>
<h3>Application</h3>
<p>Create an application class if you have none yet (don&#8217;t forget to add it to the manifest).</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
     
        startKoin {
            androidContext(this@MyApplication)
            modules(
                module {
                    single { House(get()) }
                    single&lt;Doorbell&gt; { SpeakingDoorbell() }
                }
            )
        }
    } 
}</code></pre>
</div>
<h3>Profit</h3>
<p>That&#8217;s it! This is the basic Koin setup. As you can see the House class now even fetches its needed instance of Doorbell.<br />
Simply call <strong>startKoin</strong>, configure the AndroidContext and define some Beans. These can also be injected like this into Android components like activities:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>val myVariable: MyVariableType by inject()</code></pre>
</div>
<h3>ViewModel injection</h3>
<p>The avid reader might already have noticed something. &#8220;What about our ViewModels. They have a lifecycle and should not get created just like that&#8221;.</p>
<p>To fix this issue there exists an extension for Koin.</p>
<p>Instead of declaring a Bean like that</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>single { MyClass() }
</code></pre>
</div>
<p>we use</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>viewModel&lt;MyViewModelType&gt; { MyViewModel() }
</code></pre>
</div>
<p>The injection is then done inside the fragment like that:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>val myViewModel: MyViewModelType by viewModel()
</code></pre>
</div>
<h2>Conclusion</h2>
<p>Using Dependency Injection, especially with a framework, can be intimidating for a new programmer.</p>
<p>But in the most cases the positive aspects outweigh the negatives and the complexity of setting up a dependency<br />
injection framework is quite low.</p>
<p>There are a lot of other things Koin can do like defining factories instead of singles, directly helping out with tests, instantiating fragments, or much more.</p>
<p>Have a glance at the <a href="https://insert-koin.io/docs/reference/introduction">official documentation</a></p>
<p>The post <a href="https://creatronix.de/dependency-injection-with-koin-and-kotlin-in-android/">Dependency Injection with Koin and Kotlin in Android</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to fix Camera: Camera new cameraInitNormal:-13</title>
		<link>https://creatronix.de/how-to-fix-camera-camera-new-camerainitnormal-13/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Sun, 07 Nov 2021 17:00:20 +0000</pubDate>
				<category><![CDATA[Android & iOS development]]></category>
		<category><![CDATA[Kotlin & Java]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=4037</guid>

					<description><![CDATA[<p>I&#8217;ve integrated a QRCode scanner into my app and it worked fine on my old Android 5 device but throws the error Camera: Camera new cameraInitNormal:-13 on Android 8. To fix this You have to integrate some code to check if permission is already granted by the user and in case it is not, request&#8230;</p>
<p>The post <a href="https://creatronix.de/how-to-fix-camera-camera-new-camerainitnormal-13/">How to fix Camera: Camera new cameraInitNormal:-13</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I&#8217;ve integrated a QRCode scanner into my app and it worked fine on my old Android 5 device but throws the error</p>
<pre>Camera: Camera new cameraInitNormal:-13</pre>
<p>on Android 8. To fix this You have to integrate some code to check if permission is already granted by the user and in case it is not, request the rights for it at runtime.</p>
<p>This looks like this:</p>
<pre>override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    val scannerView = binding.scannerView
    val activity = requireActivity()

    <strong>if (ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA)</strong>
<strong>        != PackageManager.PERMISSION_GRANTED) {</strong>
<strong>        ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.CAMERA), 50);</strong>
<strong>    }</strong></pre>
<p>Now the user is asked every time when the camera feature shall be accessed:</p>
<p><img fetchpriority="high" decoding="async" class="alignnone size-large wp-image-4039" src="https://creatronix.de/wp-content/uploads/2021/11/img_2462-1024x768.jpg" alt="" width="525" height="394" srcset="https://creatronix.de/wp-content/uploads/2021/11/img_2462-1024x768.jpg 1024w, https://creatronix.de/wp-content/uploads/2021/11/img_2462-300x225.jpg 300w, https://creatronix.de/wp-content/uploads/2021/11/img_2462-768x576.jpg 768w, https://creatronix.de/wp-content/uploads/2021/11/img_2462-1536x1152.jpg 1536w, https://creatronix.de/wp-content/uploads/2021/11/img_2462-2048x1536.jpg 2048w" sizes="(max-width: 525px) 100vw, 525px" /></p>
<p>The post <a href="https://creatronix.de/how-to-fix-camera-camera-new-camerainitnormal-13/">How to fix Camera: Camera new cameraInitNormal:-13</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to use Snackbars</title>
		<link>https://creatronix.de/how-to-use-snackbars/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Tue, 26 Oct 2021 14:16:25 +0000</pubDate>
				<category><![CDATA[Android & iOS development]]></category>
		<category><![CDATA[Kotlin & Java]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[material desing]]></category>
		<category><![CDATA[snackbar]]></category>
		<category><![CDATA[toast]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=3940</guid>

					<description><![CDATA[<p>A Snackbar is a replacement for Toasts in Android. Dependency implementation 'com.google.android.material:material:1.4.0' Layout A snackbar must be tied to a coordinator layout. If you use fragments the standard layout is FrameLayout which can be directly swapped with: &#60;androidx.coordinatorlayout.widget.CoordinatorLayout Snackbar val snackbar = Snackbar.make( binding.root, "No internet connection! Please enable WiFi or Mobile Data", Snackbar.LENGTH_INDEFINITE )&#8230;</p>
<p>The post <a href="https://creatronix.de/how-to-use-snackbars/">How to use Snackbars</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A Snackbar is a replacement for Toasts in Android.</p>
<h2>Dependency</h2>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-groovy" data-lang="Groovy"><code>implementation 'com.google.android.material:material:1.4.0'</code></pre>
</div>
<h2>Layout</h2>
<p>A snackbar must be tied to a coordinator layout. If you use fragments the standard layout is FrameLayout which can be directly swapped with:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-xml" data-lang="XML"><code>&lt;androidx.coordinatorlayout.widget.CoordinatorLayout</code></pre>
</div>
<h2>Snackbar</h2>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-kotlin" data-lang="Kotlin"><code>val snackbar = Snackbar.make( 
    binding.root, 
    "No internet connection! Please enable WiFi or Mobile Data", 
    Snackbar.LENGTH_INDEFINITE ) 
snackbar.show()</code></pre>
</div>
<h2>Further Reading</h2>
<p><a href="https://creatronix.de/passing-data-between-fragments-using-safeargs/">Passing data between fragments using SafeArgs</a></p>
<p><a href="https://creatronix.de/dependency-injection-with-koin-and-kotlin-in-android/">Dependency Injection with Koin and Kotlin in Android</a></p>
<p><a href="https://creatronix.de/how-to-use-viewmodel/">How to use ViewModel in Android</a></p>
<p>The post <a href="https://creatronix.de/how-to-use-snackbars/">How to use Snackbars</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Logging in Android</title>
		<link>https://creatronix.de/logging-in-android/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Mon, 25 Oct 2021 08:33:28 +0000</pubDate>
				<category><![CDATA[Android & iOS development]]></category>
		<category><![CDATA[Kotlin & Java]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=3895</guid>

					<description><![CDATA[<p>Logging brings some light into the darkness of your code. If you are new to logging please have a look at Log4j2 for Kotlin Import import android.util.Log Tag class MainActivity : AppCompatActivity() { companion object { const val TAG = "MainActivity" } Log statement override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Log.d(TAG, "onCreate") } Logcat Further&#8230;</p>
<p>The post <a href="https://creatronix.de/logging-in-android/">Logging in Android</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Logging brings some light into the darkness of your code. If you are new to logging please have a look at <a href="https://creatronix.de/log4j2-for-kotlin/">Log4j2 for Kotlin</a></p>
<h2>Import</h2>
<pre>import android.util.Log</pre>
<h2>Tag</h2>
<pre>class MainActivity : AppCompatActivity() {
    companion object {
        <strong>const val TAG = "MainActivity"</strong>
    }</pre>
<h2>Log statement</h2>
<pre>override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    <strong>Log.d(TAG, "onCreate")</strong>
}</pre>
<h2>Logcat</h2>
<p><img decoding="async" class="alignnone size-full wp-image-3898" src="https://creatronix.de/wp-content/uploads/2021/10/logcat.png" alt="" width="942" height="278" srcset="https://creatronix.de/wp-content/uploads/2021/10/logcat.png 942w, https://creatronix.de/wp-content/uploads/2021/10/logcat-300x89.png 300w, https://creatronix.de/wp-content/uploads/2021/10/logcat-768x227.png 768w" sizes="(max-width: 942px) 100vw, 942px" /></p>
<h2>Further Reading</h2>
<p><a href="https://creatronix.de/stetho-a-debug-bridge-for-android-applications/">Stetho: A debug bridge for Android applications</a></p>
<p><a href="https://creatronix.de/dependency-injection-with-koin-and-kotlin-in-android/">Dependency Injection with Koin and Kotlin in Android</a></p>
<p><a href="https://creatronix.de/versioncode-vs-versionname-in-android-apps/">versionCode vs versionName in Android Apps</a></p>
<p>The post <a href="https://creatronix.de/logging-in-android/">Logging in Android</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Classes in Kotlin &#8211; Part 2</title>
		<link>https://creatronix.de/classes-in-kotlin-part-2/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Tue, 19 Oct 2021 06:40:39 +0000</pubDate>
				<category><![CDATA[Kotlin & Java]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[ctor]]></category>
		<category><![CDATA[init]]></category>
		<category><![CDATA[kotlin]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=3802</guid>

					<description><![CDATA[<p>In Part 1 we dealt with the simplest form of initialization with the primary constructor: class Planet( val diameter: Int, val distanceToSun: Double, val mass: Double ) But wait: there is more: Init block The primary constructor cannot contain any code so init block for the rescue: class Planet( val diameter: Int, val distanceToSun: Double,&#8230;</p>
<p>The post <a href="https://creatronix.de/classes-in-kotlin-part-2/">Classes in Kotlin &#8211; Part 2</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In<a href="https://creatronix.de/classes-in-kotlin/"> Part 1</a> we dealt with the simplest form of initialization with the primary constructor:</p>
<pre>class Planet(
    val diameter: Int,
    val distanceToSun: Double,
    val mass: Double
)</pre>
<p>But wait: there is more:</p>
<h2>Init block</h2>
<p>The primary constructor cannot contain any code so init block for the rescue:</p>
<pre>class Planet(
    val diameter: Int,
    val distanceToSun: Double,
    val mass: Double
) {
    val circumference = PI * diameter
    init {
        println(circumference)
    }
}</pre>
<p>Notes:</p>
<ul>
<li>You can have more than one init block</li>
<li>they run in order of their declaration</li>
</ul>
<p>The post <a href="https://creatronix.de/classes-in-kotlin-part-2/">Classes in Kotlin &#8211; Part 2</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Classes in Kotlin &#8211; Part 1</title>
		<link>https://creatronix.de/classes-in-kotlin/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Fri, 15 Oct 2021 07:21:41 +0000</pubDate>
				<category><![CDATA[Kotlin & Java]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=3784</guid>

					<description><![CDATA[<p>Why is there a car in the picture? &#8211; Because it has class! Jokes aside, classes are still the building blocks of modern object oriented software design. And of course as the new kid on the block Kotlin has it&#8217;s own take on this subject. Declaration Let&#8217;s look at the most basic class declaration: class&#8230;</p>
<p>The post <a href="https://creatronix.de/classes-in-kotlin/">Classes in Kotlin &#8211; Part 1</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Why is there a car in the picture? &#8211; Because it has class!</p>
<p>Jokes aside, classes are still the building blocks of modern object oriented software design. And of course as the new kid on the block Kotlin has it&#8217;s own take on this subject.</p>
<h2>Declaration</h2>
<p>Let&#8217;s look at the most basic class declaration:</p>
<pre>class Earth{     
  val diameter = 12756     
  val distanceToSun = 149.6e6     
  val mass = 5.9724e24 
}</pre>
<p>&nbsp;</p>
<h2>Initialization</h2>
<pre>class Planet(     
  val diameter: Int,     
  val distanceToSun: Double,     
  val mass: Double
 )</pre>
<h2>Instantiation</h2>
<pre>fun main() {     
  val earth = Planet(diameter = 12756, distanceToSun = 149.6e6, mass = 5.9724e24)     
  println(earth.diameter)     
  println(earth.distanceToSun)     
  println(earth.mass)
}</pre>
<p>The post <a href="https://creatronix.de/classes-in-kotlin/">Classes in Kotlin &#8211; Part 1</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
