<?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 Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/tag/kotlin/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/tag/kotlin/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Thu, 23 Oct 2025 13:10:22 +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>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>Kotlinx Datetime</title>
		<link>https://creatronix.de/kotlinx-datetime/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Tue, 12 Oct 2021 10:37:55 +0000</pubDate>
				<category><![CDATA[Kotlin & Java]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[kotlin]]></category>
		<category><![CDATA[kotlinx]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=3582</guid>

					<description><![CDATA[<p>Dependency Add the following to your dependencies implementation(org.jetbrains.kotlinx:kotlinx-datetime:0.2.0) Usage import kotlinx.datetime.* val today = Clock.System.todayAt(TimeZone.currentSystemDefault()) If you target Android devices running below API 26, you need to use Android Gradle plugin 4.0 or newer and enable core library desugaring. https://github.com/Kotlin/kotlinx-datetime</p>
<p>The post <a href="https://creatronix.de/kotlinx-datetime/">Kotlinx Datetime</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Dependency</h2>
<p>Add the following to your dependencies</p>
<pre>implementation(org.jetbrains.kotlinx:kotlinx-datetime:0.2.0)
</pre>
<h2>Usage</h2>
<pre>import kotlinx.datetime.*
val today = Clock.System.todayAt(TimeZone.currentSystemDefault())</pre>
<p>If you target Android devices running below API 26, you need to use Android Gradle plugin 4.0 or newer and enable core library desugaring.</p>
<p><a href="https://github.com/Kotlin/kotlinx-datetime">https://github.com/Kotlin/kotlinx-datetime</a></p>
<p>The post <a href="https://creatronix.de/kotlinx-datetime/">Kotlinx Datetime</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Pass custom objects via SafeArgs</title>
		<link>https://creatronix.de/pass-custom-objects-via-safeargs/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Tue, 28 Sep 2021 14:26:07 +0000</pubDate>
				<category><![CDATA[Android & iOS development]]></category>
		<category><![CDATA[Kotlin & Java]]></category>
		<category><![CDATA[gradle]]></category>
		<category><![CDATA[kotlin]]></category>
		<category><![CDATA[parcelable]]></category>
		<category><![CDATA[parcelize]]></category>
		<category><![CDATA[safe args]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=3711</guid>

					<description><![CDATA[<p>In Passing data between fragments using SafeArgs I showed You how to pass data between -well-  fragments. This included all basic / built-in types like Strings and Integers. In this part I will show you how you can pass custom objects. Peprare your class To use a custom class for passing between fragments it has&#8230;</p>
<p>The post <a href="https://creatronix.de/pass-custom-objects-via-safeargs/">Pass custom objects via SafeArgs</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In <a href="https://creatronix.de/passing-data-between-fragments-using-safeargs/">Passing data between fragments using SafeArgs</a> I showed You how to pass data between -well-  fragments.</p>
<p>This included all basic / built-in types like Strings and Integers.</p>
<p>In this part I will show you how you can pass custom objects.<span id="more-3711"></span></p>
<h2>Peprare your class</h2>
<p>To use a custom class for passing between fragments it has to be of type Parcelable and you must use the annotation @Parcelize</p>
<pre>import android.os.Parcelable
import kotlinx.parcelize.Parcelize

<strong>@Parcelize</strong>
class VideoPlayListItem(val videoID: String, val videoTitle: String): <strong>Parcelable</strong> {

}</pre>
<h2>Gradle Plugin</h2>
<p>Add kotlin-parcelize to your module gradle.build</p>
<pre>plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'androidx.navigation.safeargs.kotlin'
    <strong>id "kotlin-parcelize"</strong></pre>
<h2>Add argument in nav_graph.xml</h2>
<pre>&lt;fragment
    android:id="@+id/VideoPlayerFragment"
    android:name="de.creatronix.levelup.fragments.VideoPlayerFragment"
    android:label="@string/video_player_fragment_label"
    tools:layout="@layout/fragment_video_player"&gt;

    &lt;argument
        android:name="video"
        app:argType="<strong>de.creatronix.levelup.VideoPlayListItem</strong>" /&gt;
&lt;/fragment&gt;</pre>
<h2>Pass data to fragment action</h2>
<pre>val action =
    VideoFragmentDirections.actionVideoFragmentToVideoPlayerFragment(
        clickedItem
    )
findNavController().navigate(action)</pre>
<p>The post <a href="https://creatronix.de/pass-custom-objects-via-safeargs/">Pass custom objects via SafeArgs</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Log4j2 PatternLayout Cheatsheet</title>
		<link>https://creatronix.de/log4j2-patternlayout-cheatsheet/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Tue, 27 Apr 2021 09:22:47 +0000</pubDate>
				<category><![CDATA[Kotlin & Java]]></category>
		<category><![CDATA[kotlin]]></category>
		<category><![CDATA[log4j2]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[patternlayout]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=3567</guid>

					<description><![CDATA[<p>In Log4j2 for Kotlin I&#8217;ve showed you how to configure a basic logger with log4j2. If you use a PatternLayout like this appender.console.layout.type = PatternLayout appender.console.layout.pattern = %m%n you can customize the appearance of the output. eg. appender.console.layout.pattern = %d{yyyy-mm-dd-HH:mm:ss.SSS} %-4p %C{1}.%M [%t] - %m%n%ex Parameter Parameter Meaning %m The log message %n line break&#8230;</p>
<p>The post <a href="https://creatronix.de/log4j2-patternlayout-cheatsheet/">Log4j2 PatternLayout Cheatsheet</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In <a href="https://creatronix.de/log4j2-for-kotlin/">Log4j2 for Kotlin</a> I&#8217;ve showed you how to configure a basic logger with log4j2.</p>
<p>If you use a PatternLayout like this</p>
<pre>appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %m%n</pre>
<p>you can customize the appearance of the output.</p>
<p>eg.</p>
<pre>appender.console.layout.pattern = %d{yyyy-mm-dd-HH:mm:ss.SSS} %-4p %C{1}.%M [%t] - %m%n%ex</pre>
<h2>Parameter</h2>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>%m</td>
<td>The log message</td>
</tr>
<tr>
<td>%n</td>
<td>line break</td>
</tr>
<tr>
<td>%d</td>
<td>timestamp</td>
</tr>
<tr>
<td>%p</td>
<td>priority</td>
</tr>
<tr>
<td>%t</td>
<td>thread</td>
</tr>
<tr>
<td>%C</td>
<td>class</td>
</tr>
</tbody>
</table>
<h2>Timestamps</h2>
<p>&nbsp;</p>
<pre>%d{yyyy-mm-dd-HH:mm:ss.SSS}
2021-50-27-10:50:32.701</pre>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>yyyy</td>
<td>year in four digits</td>
</tr>
<tr>
<td>MM</p>
<p>MMM</td>
<td>month in two digits</p>
<p>Name of month three characters wide</td>
</tr>
<tr>
<td>dd</td>
<td>day</td>
</tr>
<tr>
<td>HH</td>
<td>hour</td>
</tr>
<tr>
<td>mm</td>
<td>minutes</td>
</tr>
<tr>
<td>ss</td>
<td>seconds</td>
</tr>
<tr>
<td>SSS</td>
<td>milliseconds</td>
</tr>
</tbody>
</table>
<p>The post <a href="https://creatronix.de/log4j2-patternlayout-cheatsheet/">Log4j2 PatternLayout Cheatsheet</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Log4j2 for Kotlin</title>
		<link>https://creatronix.de/log4j2-for-kotlin/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Tue, 20 Apr 2021 13:40:00 +0000</pubDate>
				<category><![CDATA[Kotlin & Java]]></category>
		<category><![CDATA[cook book]]></category>
		<category><![CDATA[gradle]]></category>
		<category><![CDATA[kotlin]]></category>
		<category><![CDATA[log4j2]]></category>
		<category><![CDATA[logger]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[recipe]]></category>
		<category><![CDATA[Zero-Day Exploit]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=3555</guid>

					<description><![CDATA[<p>Motivation Logging is a common good practice in software engineering. It enables you to monitor applications in production to gather information about crashes and other malfunctions for further analysis. It is the &#8220;little brother&#8221; of debugging and often a precursor for setting up test cases which can lead to reproducing the bugs on the developers&#8230;</p>
<p>The post <a href="https://creatronix.de/log4j2-for-kotlin/">Log4j2 for Kotlin</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Motivation</h2>
<p>Logging is a common good practice in software engineering. It enables you to monitor applications in production to gather information about crashes and other malfunctions for further analysis. It is the &#8220;little brother&#8221; of debugging and often a precursor for setting up test cases which can lead to reproducing the bugs on the developers machine.</p>
<p>Log4j2 is version 2 of the very famous Apache logging library log4j from the Java ecosystem.</p>
<p>This article describes a minimal working solution for log4j2 with Kotlin and Gradle.</p>
<h2>Dependencies</h2>
<p>To get started with log4j2 add the following lines to your build.gradle file in the dependency section:</p>
<pre>implementation 'org.apache.logging.log4j:log4j-api:2.15.0'
implementation 'org.apache.logging.log4j:log4j-core:2.15.0'</pre>
<p><strong>Please make sure to use the latest </strong><del>2.15.0</del><strong> 2.16.0 to avoid the Zero-Day Exploit! <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-45046">More Details</a><br />
</strong></p>
<h2>Configuration</h2>
<p>Create a file with the name log4j2.properties under src/resources with the content:</p>
<pre>status = error

appender.console.type = Console
appender.console.name = LogToConsole
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %m%n

rootLogger.level = error
rootLogger.appenderRef.stdout.ref = LogToConsole</pre>
<h2>Logger</h2>
<p>In your code you can insert the log statements the following way:</p>
<pre>import org.apache.logging.log4j.kotlin.logger

fun main() {
    val log = logger("Main")
    log.trace("Trace")
    log.debug("Debug")
    log.info("Info")
    log.warn("Warn")
    log.error("Error")
    log.fatal("Fatal")
}</pre>
<h2>Log Levels</h2>
<p>In the configuration file you can set the log level.</p>
<p>e.g. rootLogger.level = error will log all log message which are more severe than error including error -&gt; (fatal and error)</p>
<pre>| Log msg |        |       |       |      |      |       |       |     |
|---------|--------|-------|-------|------|------|-------|-------|-----|
| trace   |        |       |       |      |      |       | x     | x   |
| debug   |        |       |       |      |      | x     | x     | x   |
| info    |        |       |       |      | x    | x     | x     | x   |
| warn    |        |       |       | x    | x    | x     | x     | x   |
| error   |        |       | x     | x    | x    | x     | x     | x   |
| fatal   |        | x     | x     | x    | x    | x     | x     | x   |
|         | off    | fatal | error | warn | info | debug | trace | all |
|         | config |       |       |      |      |       |       |     |</pre>
<p>The post <a href="https://creatronix.de/log4j2-for-kotlin/">Log4j2 for Kotlin</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Kotlin Scripts with Gradle</title>
		<link>https://creatronix.de/kotlin-scripts-with-gradle/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Tue, 20 Apr 2021 13:20:44 +0000</pubDate>
				<category><![CDATA[Kotlin & Java]]></category>
		<category><![CDATA[build.gradle]]></category>
		<category><![CDATA[gradle]]></category>
		<category><![CDATA[kotlin]]></category>
		<category><![CDATA[script]]></category>
		<guid isPermaLink="false">https://creatronix.de/?p=3553</guid>

					<description><![CDATA[<p>If you are using Gradle and you want to run a Kotlin script you have to add the following to your build.gradle file dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib" implementation 'org.jetbrains.kotlin:kotlin-script-runtime:1.4.32' }</p>
<p>The post <a href="https://creatronix.de/kotlin-scripts-with-gradle/">Kotlin Scripts with Gradle</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>If you are using Gradle and you want to run a Kotlin script you have to add the following to your build.gradle file</p>
<pre>dependencies {
     implementation "org.jetbrains.kotlin:kotlin-stdlib"
     implementation 'org.jetbrains.kotlin:kotlin-script-runtime:1.4.32'
}</pre>
<p>The post <a href="https://creatronix.de/kotlin-scripts-with-gradle/">Kotlin Scripts with Gradle</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Passing data between AndroidActivities</title>
		<link>https://creatronix.de/passing-data-between-androidactivities/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Wed, 17 Jun 2020 14:29:21 +0000</pubDate>
				<category><![CDATA[Android & iOS development]]></category>
		<category><![CDATA[Kotlin & Java]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[extra]]></category>
		<category><![CDATA[intent]]></category>
		<category><![CDATA[kotlin]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=3341</guid>

					<description><![CDATA[<p>Sending data private void openVideoActivity(String video) { Intent newActivity = new Intent(this, PlayerActivity.class); newActivity.putExtra("videoId", video); startActivity(newActivity); } Retrieving data final String videoID = getIntent().getExtras().getString("videoID"); &#160; In Kotlin it looks like this: val intent = Intent(this, NewActivity::class.java).apply { putExtra("EXTRA_MESSAGE", "Test 123") } startActivity(intent) Retrieving val message = intent.getStringExtra("EXTRA_MESSAGE") Further Reading Passing data between fragments using SafeArgs&#8230;</p>
<p>The post <a href="https://creatronix.de/passing-data-between-androidactivities/">Passing data between AndroidActivities</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Sending data</h2>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Java"><code>private void openVideoActivity(String video) {
    Intent newActivity = new Intent(this, PlayerActivity.class);
    newActivity.putExtra("videoId", video);
    startActivity(newActivity);
}</code></pre>
</div>
<h2>Retrieving data</h2>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Java"><code>final String videoID = getIntent().getExtras().getString("videoID");</code></pre>
</div>
<p>&nbsp;</p>
<p>In Kotlin it looks like this:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>val intent = Intent(this, NewActivity::class.java).apply {
    putExtra("EXTRA_MESSAGE", "Test 123")
}
startActivity(intent)</code></pre>
</div>
<p>Retrieving</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>val message = intent.getStringExtra("EXTRA_MESSAGE")</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/pass-custom-objects-via-safeargs/">Pass custom objects via SafeArgs</a></p>
<p>The post <a href="https://creatronix.de/passing-data-between-androidactivities/">Passing data between AndroidActivities</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Android App Lifecycle</title>
		<link>https://creatronix.de/android-app-lifecycle/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Fri, 22 May 2020 08:11:04 +0000</pubDate>
				<category><![CDATA[Android & iOS development]]></category>
		<category><![CDATA[Kotlin & Java]]></category>
		<category><![CDATA[andorid]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[kotlin]]></category>
		<category><![CDATA[lifecycle]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=3282</guid>

					<description><![CDATA[<p>Code class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) Log.d("LifecycleTest", "onCreate") } override fun onStart() { super.onStart() Log.d("LifecycleTest", "onStart") } override fun onResume() { super.onResume() Log.d("LifecycleTest", "onResume") } override fun onPause() { super.onPause() Log.d("LifecycleTest", "onPause") } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) Log.d("LifecycleTest", "onSaveInstanceState") } override fun onRestoreInstanceState(savedInstanceState: Bundle) { Log.d("LifecycleTest",&#8230;</p>
<p>The post <a href="https://creatronix.de/android-app-lifecycle/">Android App Lifecycle</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img fetchpriority="high" decoding="async" class="alignnone wp-image-3286 size-full" src="https://creatronix.de/wp-content/uploads/2020/05/app_lifecycle.png" alt="" width="1200" height="309" srcset="https://creatronix.de/wp-content/uploads/2020/05/app_lifecycle.png 1200w, https://creatronix.de/wp-content/uploads/2020/05/app_lifecycle-300x77.png 300w, https://creatronix.de/wp-content/uploads/2020/05/app_lifecycle-1024x264.png 1024w, https://creatronix.de/wp-content/uploads/2020/05/app_lifecycle-768x198.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></p>
<h2>Code</h2>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-kotlin" data-lang="Kotlin"><code>class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        Log.d("LifecycleTest", "onCreate")
    }

    override fun onStart() {
        super.onStart()
        Log.d("LifecycleTest", "onStart")
    }

    override fun onResume() {
        super.onResume()
        Log.d("LifecycleTest", "onResume")
    }

    override fun onPause() {
        super.onPause()
        Log.d("LifecycleTest", "onPause")
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        Log.d("LifecycleTest", "onSaveInstanceState")
    }

    override fun onRestoreInstanceState(savedInstanceState: Bundle) {
        Log.d("LifecycleTest", "onSaveInstanceState")
    }

    override fun onStop() {
        super.onStop()
        Log.d("LifecycleTest", "onStop")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d("LifecycleTest", "onDestroy")
    }
}</code></pre>
<p><a href="https://github.com/jboegeholz/LifecycleTest">https://github.com/jboegeholz/LifecycleTest</a></p>
</div>
<p>The post <a href="https://creatronix.de/android-app-lifecycle/">Android App Lifecycle</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Learning Kotlin &#8211; Part 4 &#8211; conditionals</title>
		<link>https://creatronix.de/learning-kotlin-part-4/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Mon, 03 Jun 2019 08:12:33 +0000</pubDate>
				<category><![CDATA[Kotlin & Java]]></category>
		<category><![CDATA[conditionals]]></category>
		<category><![CDATA[else]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[kotlin]]></category>
		<category><![CDATA[when]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=2691</guid>

					<description><![CDATA[<p>Conditionals This is a pretty quick one: Kotlin has the standard Java if / else if / else statements val age = 12 if (age &#60; 5) { println("Go to kindergarten") } else if (age == 5) { println("Go to pre-school") } else if (age &#62; 5 &#38;&#38; age &#60;= 17) { println("Go to grade&#8230;</p>
<p>The post <a href="https://creatronix.de/learning-kotlin-part-4/">Learning Kotlin &#8211; Part 4 &#8211; conditionals</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Conditionals</h2>
<p>This is a pretty quick one:</p>
<p>Kotlin has the standard Java if / else if / else statements</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>val age = 12

if (age &lt; 5) {
    println("Go to kindergarten")
} else if (age == 5) {
    println("Go to pre-school")
} else if (age &gt; 5 &amp;&amp; age &lt;= 17) {
    println("Go to grade ${age - 5}")
} else {
    println("Go to college!")
}</code></pre>
</div>
<p>But one nice feature is the when clause:</p>
<p>It feels like a mixture of switch/case and if/else with a flavor of ranges 🙂</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>when (age) { 
    0, 1, 2, 3, 4 -&gt; println("Go to preschool") 
    5 -&gt; println("Go to Kindergarten") 
    in 6..17 -&gt; { 
        val grade = age - 5 println("Go to grade $grade") 
    } 
    else -&gt; println("Go to college!") 
}</code></pre>
</div>
<p><a href="https://creatronix.de/learning-kotlin-part-5/">Ready for Part 5?</a></p>
<p>The post <a href="https://creatronix.de/learning-kotlin-part-4/">Learning Kotlin &#8211; Part 4 &#8211; conditionals</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Learning Kotlin &#8211; Part 1 &#8211; strings and print</title>
		<link>https://creatronix.de/learning-kotlin-part-1/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Fri, 17 May 2019 08:45:31 +0000</pubDate>
				<category><![CDATA[Kotlin & Java]]></category>
		<category><![CDATA[kotlin]]></category>
		<category><![CDATA[string interpolation]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=2654</guid>

					<description><![CDATA[<p>Motivation I wanted to try writing an Android app. In spite of using plain old Java I wanted to give the new kid on the block Kotlin (from the Jetbrains folks) a try. First observations Coming from a Python background it&#8217;s good to see that Kotlin doesn&#8217;t use semi-colons! But the curly braces from Java&#8230;</p>
<p>The post <a href="https://creatronix.de/learning-kotlin-part-1/">Learning Kotlin &#8211; Part 1 &#8211; strings and print</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Motivation</h2>
<p><img decoding="async" class="alignnone size-full wp-image-2664" src="https://creatronix.de/wp-content/uploads/2019/05/Kotlin-logo.png" alt="" width="152" height="151" srcset="https://creatronix.de/wp-content/uploads/2019/05/Kotlin-logo.png 152w, https://creatronix.de/wp-content/uploads/2019/05/Kotlin-logo-150x150.png 150w, https://creatronix.de/wp-content/uploads/2019/05/Kotlin-logo-100x100.png 100w" sizes="(max-width: 152px) 100vw, 152px" /></p>
<p>I wanted to try writing an Android app. In spite of using plain old Java I wanted to give the new kid on the block <a href="https://kotlinlang.org/">Kotlin</a> (from the Jetbrains folks) a try.</p>
<h2>First observations</h2>
<p>Coming from a Python background it&#8217;s good to see that Kotlin doesn&#8217;t use semi-colons! But the curly braces from Java make code blocks are still there, hmpf&#8230;</p>
<h2>Variables</h2>
<p>Kotlin has two ways of declaring &#8220;variables&#8221;:</p>
<ul>
<li>va<strong>r</strong>: think variable: this is a mutable</li>
<li>va<strong>l</strong>: think values: this is read-only like const</li>
</ul>
<h2>Data Types and Type Inference</h2>
<p>A nice thing about Kotlin is type inference. When it is clear which data type is meant you can leave out the data type from the declaration</p>
<h3>Strings</h3>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>val firstName = "Tony" 
val lastName = "Stark"</code></pre>
</div>
<h4>Concatenation</h4>
<p>You can concatenate strings with the plus operator as you can do it in Python</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>val fullName: String = firstName + " " + lastName</code></pre>
</div>
<h4>Print and String interpolation</h4>
<p>Kotlin has a built-in println function so you can stop typing System.out.println()</p>
<p>Less visual noise!</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>println(fullName)</code></pre>
</div>
<p>A neat little feature is the string interpolation syntax. If You want to concatenate strings for logging output, you can write $stringName Locks similar to the Python <a href="https://creatronix.de/f-strings-in-python/">f-Strings</a></p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>println("Name: $fullName")</code></pre>
</div>
<p>But there is more to it:<br />
You can for example call functions inside strings as well:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>println("String length: ${fullName.length}")</code></pre>
</div>
<p>or access indices</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-java" data-lang="Kotlin"><code>println("2nd Index: ${fullName[2]}")</code></pre>
</div>
<p><a href="https://creatronix.de/learning-kotlin-part-2/">Ready for Part 2?</a></p>
<p>The post <a href="https://creatronix.de/learning-kotlin-part-1/">Learning Kotlin &#8211; Part 1 &#8211; strings and print</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
