<?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 Hicran Filiz on Medium]]></title>
        <description><![CDATA[Stories by Hicran Filiz on Medium]]></description>
        <link>https://medium.com/@hicranfiliz?source=rss-6e0c840bca2c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vacRmTiVRLsVME0No5HZaw.png</url>
            <title>Stories by Hicran Filiz on Medium</title>
            <link>https://medium.com/@hicranfiliz?source=rss-6e0c840bca2c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 18:44:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hicranfiliz/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[Android Intents and Intent Filters]]></title>
            <link>https://medium.com/@hicranfiliz/android-intents-and-intent-filters-8ddea86a537a?source=rss-6e0c840bca2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ddea86a537a</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[intentfilter]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[intent]]></category>
            <dc:creator><![CDATA[Hicran Filiz]]></dc:creator>
            <pubDate>Thu, 02 Jan 2025 19:35:00 GMT</pubDate>
            <atom:updated>2025-01-02T19:35:00.414Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*FR7bLeQTK5zMHa_IWkItvw.jpeg" /></figure><p>One of the fundamental components of Android application development, <strong>intents</strong> and <strong>intent filters</strong>, provide an effective way to enable communication between apps and create dynamic interactions. In this article, we will explore what intents and intent filters are, how they are used, and key considerations during development.</p><h4>1. What is an Intent?</h4><ul><li>Intents represent a “purpose” or “intention” of your app. You can think of them as an envelope carrying your app’s intention to another Android component.</li><li>For example: Starting an activity or launching another app.</li><li><strong>Purpose: </strong>Typically used to start an activity.</li><li>Can also communicate with other components like services or broadcasts.</li></ul><h4>2. Types of Intents</h4><p><em>a) Explicit Intents: </em>Used to target a specific component.</p><ul><li>Examples: Starting an activity within your own app.</li><li>Launching a specific activity in another app (opening the YouTube app).</li></ul><p><em>b) Implicit Intents:</em> Do not target a specific component; instead, they specify a general action.</p><ul><li>For example, opening a file or sending an email.</li><li>Android provides a list of apps capable of handling the intent and lets the user choose.</li></ul><h4>3. Starting Your Activity with Explicit Intent</h4><ul><li>Create a new <strong>Activity</strong> class (<em>SecondActivity</em>).</li><li>Add it to the <strong>AndroidManifest</strong> file.</li><li>Create an<em> Intent</em> and call <em>startActivity</em> when a button is clicked.</li></ul><pre>val intent = Intent(this, SecondActivity::class.java)<br>startActivity(intent)</pre><h4>4. Starting Another App with Explicit Intent</h4><ul><li>Use the package name to launch another app.</li><li>Use <strong>adb(Android Debug Bridge)</strong> to find package names.</li></ul><pre>val intent = Intent(Intent.ACTION_MAIN)<br>intent.setPackage(&quot;com.google.android.youtube&quot;)<br>startActivity(intent)</pre><h4>5. Performing Actions with Implicit Intents</h4><ul><li>Specify an action (sending an email).</li><li>Add data using Intent.EXTRA_* (recipient, subject, content).</li></ul><pre>val intent = Intent(Intent.ACTION_SEND).apply {<br>    type = &quot;text/plain&quot;<br>    putExtra(Intent.EXTRA_EMAIL, arrayOf(&quot;test@example.com&quot;))<br>    putExtra(Intent.EXTRA_SUBJECT, &quot;My Subject&quot;)<br>    putExtra(Intent.EXTRA_TEXT, &quot;Email content&quot;)<br>}<br>startActivity(Intent.createChooser(intent, &quot;Choose an Email client&quot;))</pre><h4>6. What is an Intent Filter and How is it Used?</h4><ul><li>Used to let an app receive specific intents.</li><li>Added to the <strong>Manifest</strong> file.</li><li>Example: Listening for a share action:</li></ul><pre>&lt;intent-filter&gt;<br>    &lt;action android:name=&quot;android.intent.action.SEND&quot; /&gt;<br>    &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;<br>    &lt;data android:mimeType=&quot;image/*&quot; /&gt;<br>&lt;/intent-filter&gt;</pre><h4>7. Receiving Shared Data</h4><ul><li>Retrieve data via <strong>intent extras</strong> or URI.</li></ul><pre>override fun onNewIntent(intent: Intent) {<br>    super.onNewIntent(intent)<br>    val imageUri = intent.getParcelableExtra&lt;Uri&gt;(Intent.EXTRA_STREAM)<br>    // Load the image using the URI<br>}</pre><p><strong>Intents</strong> are a powerful way to enable communication between Android components. Explicit and Implicit Intents cater to different use cases.</p><p><strong>Intent Filters</strong> allow your app to receive specific intents.</p><p>By mastering these concepts, you can create dynamic and user-friendly experiences in your Android applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ddea86a537a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Context in Android]]></title>
            <link>https://medium.com/@hicranfiliz/context-in-android-5677d551fab2?source=rss-6e0c840bca2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5677d551fab2</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[context]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Hicran Filiz]]></dc:creator>
            <pubDate>Mon, 23 Dec 2024 19:30:57 GMT</pubDate>
            <atom:updated>2024-12-23T19:30:57.354Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*k08oxZ-Ob4nUq2ko3QuQVw.png" /></figure><h4>What is Context?</h4><p>Context is a fundamental concept in Android that represents the current state of the application. It provides access to resources, system services, and various environmental information. Each component in an Android application (Activity, Service, Fragment, etc.) operates within a specific type of Context.</p><h4>Types of Context:</h4><p><strong>1. Application Context</strong></p><ul><li>Represents the global context of the application.</li><li>Exists throughout the application’s lifecycle.</li><li>Used for long-running operations or accessing application-wide resources.</li><li>Can be accessed via applicationContext or getApplicationContext().</li></ul><p><strong>2. Activity Context</strong></p><ul><li>Linked to a specific activity.</li><li>Used for UI-related operations or accessing resources tied to that activity.</li><li>Can be accessed using this or ActivityName.this.</li></ul><p><strong>3. Service Context</strong></p><ul><li>Linked to a specific service.</li><li>Used for long-running background operations.</li><li>Can be accessed using this or ServiceName.this.</li></ul><p><strong>4. Broadcast Receiver Context</strong></p><ul><li>Provided in the onReceive method of a Broadcast Receiver.</li><li>Used to respond to broadcasts from the system or other applications.</li></ul><h4><strong>Context Need</strong></h4><p><strong>Accessing Resources :</strong></p><p>Provides access to application resources such as strings, layouts, and drawables:</p><pre>val appName = context.getString(R.string.app_name)</pre><p><strong>Accessing System Services :</strong></p><p>Allows interaction with system services like the notification manager or alarm manager:</p><pre>val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager</pre><p><strong>Launching Components :</strong></p><p>Used to start new activities, services, or broadcast receivers:</p><pre>val intent = Intent(context, TargetActivity::class.java)<br>context.startActivity(intent)</pre><p><strong>Database and File Operations :</strong></p><p>Enables access to databases or file directories of the application:</p><pre>val database = context.openOrCreateDatabase(&quot;mydb&quot;, Context.MODE_PRIVATE, null)</pre><p><strong>Permission Management :</strong></p><p>Essential for requesting and handling user permissions:</p><pre>ActivityCompat.requestPermissions(context as Activity, permissionsArray, requestCode)</pre><p><strong>View Inflation :</strong></p><p>Used to load views from XML layouts:</p><pre>val view = LayoutInflater.from(context).inflate(R.layout.custom_view, parent, false)</pre><p><strong>Broadcast Receiver Usage :</strong></p><p>Facilitates response to broadcast events in the onReceive method:</p><pre>override fun onReceive(context: Context, intent: Intent) {<br>    Log.d(&quot;Broadcast&quot;, &quot;Broadcast received&quot;)<br>}</pre><p><strong>Best Practices of Context:</strong></p><ol><li><strong>Incorrect Use of Context:</strong></li></ol><ul><li>Misusing Context can lead to memory leaks. For instance, using an <strong>Activity Context</strong> for long-running operations may prevent the activity from being garbage collected.</li><li>Note: <strong>ApplicationContext</strong> does not cause memory leaks, but it should not be used all the time. For UI operations and dynamic content, a more specific context should be preferred, such as <strong>ActivityContext</strong>.</li></ul><p><strong>2. Use </strong><strong>requireContext() in Fragments</strong></p><ul><li>When working in Fragments, prefer using requireContext() to ensure you have a valid Context reference. Avoid directly using context or activity as they may be null.</li></ul><p><strong>Understanding Context in Android?</strong></p><p>Context is a structure that provides information about the current state of the application and allows access to resources, system services, and environmental data. For instance, it is used to access string resources, start an Activity, or send a notification.</p><p>The types of Context include:</p><ul><li><strong>Application Context</strong> (global for the entire app).</li><li><strong>Activity Context</strong> (specific to an Activity, used for UI operations).</li><li><strong>Service Context</strong> (used for background tasks).</li><li><strong>Broadcast Receiver Context</strong> (used for responding to broadcast events).</li></ul><p>Using the wrong type of Context can lead to memory leaks or unintended behaviors, so selecting the appropriate Context for your use case is crucial.</p><p>I hope this article has helped you understand the concept of Context in Android and the best practices for using it correctly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5677d551fab2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin Coroutines]]></title>
            <link>https://medium.com/@hicranfiliz/kotlin-coroutines-07e7188e429a?source=rss-6e0c840bca2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/07e7188e429a</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[coroutine]]></category>
            <category><![CDATA[kotlin-coroutines]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Hicran Filiz]]></dc:creator>
            <pubDate>Sun, 01 Dec 2024 17:01:00 GMT</pubDate>
            <atom:updated>2024-12-20T09:57:21.142Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*pCoeCw6X77Ds4Qo_mtQq5A.png" /></figure><p>Coroutines are a construct in Kotlin used to simplify asynchronous programming and concurency operations. Compared to threads, they are more efficient and leightweight. Let’s take a closer look at the difference between coroutines and threads and understand why coroutines are the answer.</p><p><strong>Coroutines vs Threads:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BMC3SoPFxK0lShk5oQtBkg.png" /></figure><p><strong>Context and Dispatcher Usage:</strong></p><p>A coroutine always starts with a specific context. The context defines which thread or coroutine the opration will start on.</p><ul><li><em>Dispatchers.Main:</em> Starts the coroutine on the main thread and is used when UI operations are required. This is because the UI can only be updated on the main thread.</li><li><em>Dispatchers.IO:</em> Used for data operations like networking, writing to database, or reading and writing files.</li><li><em>Dispatcers.Default:</em> Used for complex and long-running operations. It doesn’t block the main thread.</li><li><em>Dispatchers.Unconfined:</em> Launches a new thread.</li></ul><p><strong>Context Switching:</strong></p><p>One of the best feature of coroutines is their ability to switch contexts.</p><p>For example, you need to make a network request and display the result on the UI. However, making a network on the main thread is not allowed. The main thread should only handle UI updates. Coroutines solve this problem. Simply launch a coroutine in the IO context and after making the network request, use withContext(Dispatchers.Main) to switch back to the main thread and display the result on the UI.</p><pre>viewModelScope.launch(Dispatchers.IO) {<br>    val result = fetchDataFromNetwork()<br>    withContext(Dispatchers.Main) {<br>        textView.text = result<br>    }<br>}</pre><h3>Structured Concurrency: coroutineScope vs CoroutineScope</h3><p>When working with coroutines, understanding the distinction between <em>coroutineScope</em><strong><em> </em></strong>and C<em>oroutineScope</em><strong><em> </em></strong>is critical.</p><p><strong><em>coroutineScope:</em></strong></p><ul><li>A suspending function that creates a new coroutine scope and waits for all child coroutines to complete before resuming.</li><li>Ensures <strong>structured concurrency</strong>, meaning no coroutine launched inside can outlive the <em>coroutineScope</em>.</li><li>Used within suspend functions for temporary scopes.</li></ul><pre>suspend fun performTasks() {<br>    coroutineScope {<br>        launch { <br>            // Task 1<br>        }<br>        launch { <br>            // Task 2<br>        }<br>    }<br>    // This line runs only after Task 1 and Task 2 are complete<br>}</pre><p><strong><em>CoroutineScope:</em></strong></p><ul><li>Represents a lifecycle-aware coroutine scope tied to a component like an Activity, Fragment, or ViewModel.</li><li>Coroutines launched with <em>CoroutineScope </em>live as long as the scope&#39;s lifecycle.</li><li>Often used with <em>lifecycleScope</em> or <em>viewModelScope</em>.</li></ul><pre>viewModelScope.launch {<br>    val data = fetchData()<br>    Log.d(&quot;Coroutine&quot;, &quot;Data fetched: $data&quot;)<br>}</pre><p><strong>runBlocking:</strong></p><p>The <em>delay </em>function does not block the thread it is running on. However, there is a function called <em>runBlocking</em> that starts on the main thread and blocks UI updates.</p><p><strong>Coroutine Jobs, Waiting and Cancellation:</strong></p><p>When we start a new coroutine, it actually returns a Job. We can save this as a variable.</p><pre>val job = GlobalScope.launch(Dispatchers.Default) {<br>    repeat(5) {<br>        Log(&quot;Coroutine is working...&quot;)<br>    }<br>}</pre><p>What can we do with this job?</p><ol><li>Wait for the operation to finish:</li></ol><pre>runBlocking {<br>    job.join()<br>    Log(&quot;Main thread continuing.&quot;)<br>}</pre><p>2. Cancel the operation:</p><pre>job.cancel()</pre><p>Why would we want to cancel an operation in practice? Due to timeouts. For instance, if a network operation takes too long, we might want to cancel it. Coroutines provide a very useful suspend function called <em>withTimeout.</em></p><p><strong>Async-Await:</strong></p><p>Normally, when there are multiple functions, they execute sequentially in the order they are written. However, if we want to make multiple network calls simultaneously instead of waiting for one to finish before starting the next, we should use async.</p><p>Imagine calling two suspend functions inside a coroutine, each with a 3-second delay. If we execute them one after another, the total duration would be 6 seconds. Instead, we want them to start and complete simultaneously. Here, we use <em>async</em>. To retrieve the result, we use the <em>await()</em> function, which blocks the current coroutine until the result is available.</p><p><strong>LifecycleScope and ViewModelScope:</strong></p><p>Using <em>GlobalScope</em> to launch coroutines is bad practice because it lives as long as the application does, leading to memory leaks by consuming system resources throughout the application’s lifecycle.</p><p>To solve this, use <em>lifecycleScope.launch.</em> It survives only for the activity’s lifecycle. When the activity is destroyed, the coroutine is also destroyed. Similarly, <em>viewModelScope</em> lives only as long as the ViewModel does.</p><p><strong>Conclusion:</strong></p><p>Kotlin Coroutines make asynchronous operations in Android development more readable and manageable. With context switching, suspend functions, and lifecycle-aware structures, they offer a powerful and flexible development experience. They improve the performance of your applications and enhance user experience.</p><p>Thank you for taking the time to read this article. I hope it provided you with a clear understanding of Coroutines.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=07e7188e429a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Navigation Component]]></title>
            <link>https://medium.com/@hicranfiliz/android-navigation-component-8791e731052a?source=rss-6e0c840bca2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8791e731052a</guid>
            <category><![CDATA[jetpack-navigation]]></category>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[navigation]]></category>
            <category><![CDATA[navigation-component]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Hicran Filiz]]></dc:creator>
            <pubDate>Sun, 27 Oct 2024 21:38:46 GMT</pubDate>
            <atom:updated>2024-10-27T21:59:04.901Z</atom:updated>
            <content:encoded><![CDATA[<p>The Navigation Component is a tool that enables navigation between screens in an application. In the past, navigating between activities and fragments was managed manually, which led to errors and code complexity in more complex applications. At this point, the Android Navigation Component library came into play.</p><h4>The main concepts that provide the Navigation Component are as follows:</h4><ul><li>Host: A UI element that contains the navigation destination. When the user navigates in the application, the app changes the destinations that enter and exit the navigation host. (NavHostFragment)</li><li>Graph: A data structure that defines all destinations within the application and how they connect to each other. Its type is NavGraph.</li><li>Controller: It is the central controller for navigation and destinations. It provides methods for navigation between destinations, managing deep links, and managing the back stack. Its type is NavController.</li><li>Destination: A node in the navigation graph. When a user navigates to a node, the Host displays its content. Its type is NavDestination.<br>Route: Defines a destination and the data it requires. We can perform navigation using routes. It has no specific type.</li></ul><h4>Other benefits of the Navigation Component include:</h4><ul><li>Animations and Transitions</li><li>Deep Linking</li><li>UI Patterns: Like navigation drawers and bottom navigation with minimal work</li><li>Type Safety: It allows type-safe data transfer between destinations.</li><li>ViewModel Support: Supports providing a ViewModel to the nav graph for displaying user specific data.</li><li>Fragment Transactions</li><li>Back and Up: Manages the back and up buttons correctly by default.</li></ul><h4>Setting Up the Navigation Component</h4><p>Add the following to the build.gradle file:</p><pre>// Kotlin<br>  implementation(&quot;androidx.navigation:navigation-fragment-ktx:$nav_version&quot;)<br>  implementation(&quot;androidx.navigation:navigation-ui-ktx:$nav_version&quot;)<br><br>// Testing Navigation<br>  androidTestImplementation(&quot;androidx.navigation:navigation-testing:$nav_version&quot;)</pre><h4>Adding a Host</h4><ul><li><strong>With Fragment</strong> : This method allows you to define and use a specific fragment in XML. It is not very compatible with the Navigation Component and is not suitable for complex operations.</li></ul><pre>&lt;fragment<br>    android:id=&quot;@+id/navHostFragment&quot;<br>    android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:layout_weight=&quot;1.8&quot;<br>    app:defaultNavHost=&quot;true&quot;<br>    app:navGraph=&quot;@navigation/nav_graph&quot;<br>/&gt;</pre><ul><li><strong>With FragmentContainerView</strong><em> </em>: This is the recommended method. It should be used for multiple fragments and transition operations.</li></ul><h4>Creating a Nav Graph</h4><ol><li>Create a folder named navigation under the res folder.</li><li>Under the navigation folder, create a nav_graph_xml file. In this file, define the fragments of the application and the transitions between these fragments.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_SKLZm-hLUU6U-SqDaRbw.png" /></figure><p>When you drag the start fragment and destination from one point to another in the fragment’s center, you can easily and interactively create them. Once completed, your code will look like this:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;navigation xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:id=&quot;@+id/nav_graph&quot;<br>    app:startDestination=&quot;@id/homeFragment&quot;&gt;<br><br>    &lt;fragment<br>        android:id=&quot;@+id/homeFragment&quot;<br>        android:name=&quot;com.example.bottomnavdialog.HomeFragment&quot;<br>        android:label=&quot;fragment_home&quot;<br>        tools:layout=&quot;@layout/fragment_home&quot; &gt;<br>        &lt;action<br>            android:id=&quot;@+id/action_homeFragment_to_libraryFragment&quot;<br>            app:destination=&quot;@id/libraryFragment&quot; /&gt;<br>    &lt;/fragment&gt;<br>    &lt;fragment<br>        android:id=&quot;@+id/libraryFragment&quot;<br>        android:name=&quot;com.example.bottomnavdialog.LibraryFragment&quot;<br>        android:label=&quot;fragment_library&quot;<br>        tools:layout=&quot;@layout/fragment_library&quot; &gt;<br>    &lt;/fragment&gt;<br>    <br>&lt;/navigation&gt;</pre><p>As seen, it automatically defined the action and destination between fragments.</p><p><strong><em>NOTE :</em></strong> You can define dialogs and activities inside the graph in addition to fragments.</p><p>Each fragment in the graph can have:</p><ul><li>action</li><li>argument</li><li>deeplink</li><li><strong>Argument:</strong> The argument feature is used to transfer data between fragments. This provides a safe and organized way to carry specific data when transitioning to a fragment.<br>- <strong>Deep Link: </strong>A deep link is a URI or URL link used to directly open a specific screen within an app.</li></ul><pre>&lt;fragment<br>    android:id=&quot;@+id/secondFragment&quot;<br>    android:name=&quot;com.example.SecondFragment&quot;<br>    android:label=&quot;Second Fragment&quot;&gt;<br>    &lt;argument<br>        android:name=&quot;username&quot;<br>        app:argType=&quot;string&quot; /&gt;<br>    <br>    &lt;deepLink<br>        app:uri=&quot;https://example/second/{userName}&quot; /&gt;<br>&lt;/fragment&gt;</pre><h4>Creating a Navigation Controller</h4><p>The navigation controller holds the navigation graph and provides methods for navigating between destinations in the graph. While using the Navigation Component, we need to create a navigation controller with the <strong><em>NavController</em></strong> class. It tracks which destinations the user has visited and allows navigating between destinations.</p><p>NOTE: Each NavHost corresponds to a NavController. NavController allows access to the graph of the NavHost.</p><h4>Compose:</h4><p>If using Compose, create the NavController by calling the rememberNavController function:</p><pre>val navController = rememberNavController()</pre><h4>Views:</h4><p>If using the Views UI Framework, there are three ways to access the NavController:</p><ol><li><strong>From Fragment:</strong> Fragment.findNavController()</li><li><strong>From View:</strong> View.findNavController()</li><li><strong>From Activity:</strong> Activity.findNavController(viewId: Int)</li></ol><p>First, obtain the NavHostFragment and then retrieve the NavController from that fragment. For example:</p><pre>val navHostFragment =<br>    supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment<br>val navController = navHostFragment.navController</pre><p><strong><em>NOTE :</em></strong> If you create the NavHostFragment using FragmentContainerView or manually add it using FragmentTransaction, you may encounter issues while retrieving the NavController in onCreate(). Instead, get the NavController directly from NavHostFragment.</p><p>You will not encounter issues in onResume() because by this stage, all components such as fragment, view and navHostFragment are fully loaded.</p><p>In this article, I explained how you can create a more organized navigation experience in your app with the Navigation Component. I hope you found it helpful! If you’d like to see how components like Navigation Drawer, Bottom Navigation, and Bottom Sheet Dialog are integrated, I’m sharing the project link on GitHub along with a few example images from my project. Don’t forget to check it out, and happy coding!</p><p><a href="https://github.com/hicranfiliz/NavigationComponents">https://github.com/hicranfiliz/NavigationComponents</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*msoEttxDDgMd4FvW9bRSkQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_MaXraBBs_mx6qh5UbOO7w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QI8l2u3nx9QZ3RlFZ35Yug.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8791e731052a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Tasks, Back Stack and Launch Modes]]></title>
            <link>https://medium.com/@hicranfiliz/android-tasks-back-stack-and-launch-modes-38d837b5726c?source=rss-6e0c840bca2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/38d837b5726c</guid>
            <category><![CDATA[tasks]]></category>
            <category><![CDATA[launch-mode]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[backstack]]></category>
            <dc:creator><![CDATA[Hicran Filiz]]></dc:creator>
            <pubDate>Fri, 02 Aug 2024 21:14:49 GMT</pubDate>
            <atom:updated>2024-08-02T21:14:49.891Z</atom:updated>
            <content:encoded><![CDATA[<p>In Android, launch modes define how activities are associated with tasks and how they interact with the back stack. Understanding these modes is crucial for managing the behavior and navigation of activities within your application.</p><h4>Task and Back Stack</h4><p>A <strong>task</strong> is a collection of activities that users interact with while performing a certain job. These activities are arranged in a back stack, in the order they were opened. The back stack operates on a Last In, First Out (LIFO) principle. When the user presses the back button, the current activity is popped from the stack and destroyed, revealing the previous activity. If the task is empty, it gets destroyed.</p><figure><img alt="Representation of how each new activity in a test is added to the back stack. When the user presses the back button, the current activity is destroyed and the previous activity continues." src="https://cdn-images-1.medium.com/max/617/1*M1ukvU3L12BNG19XbkrrAg.png" /><figcaption>Representation of how each new activity in a test is added to the back stack. When the user presses the back button, the current activity is destroyed and the previous activity continues.</figcaption></figure><h4>Launch Modes</h4><p>Launch modes determine how activities are launched and associated with tasks. They can be specified in two ways:</p><ol><li>In the manifest file using the ‘<em>launchMode’</em> attribute.</li><li>Using <em>intent flags</em> when starting an activity.</li></ol><p>There are 5 launch modes:</p><ul><li><strong>standard</strong></li><li><strong>singleTop</strong></li><li><strong>singleTask</strong></li><li><strong>singleInstance</strong></li><li><strong>singleInstancePerTask</strong></li></ul><p>Let’s delve into each mode:</p><h4>1. Standard</h4><p>This is the default mode. Each time an activity is launched, a new instance is created and added to the task’s back stack.</p><ul><li><strong>Definition Standard Launch Mode</strong>:</li></ul><pre>&lt;activity<br>    android:name=&quot;.StandardActivity&quot;<br>    android:label=&quot;launchMode&quot;<br>    android:launchMode=&quot;standard&quot;/&gt;</pre><ul><li><strong>Example</strong>: In an email app, opening each email in a new activity.</li><li><strong>Behavior</strong>: A→B→C→D→D (if D is launched again, a new instance is created)</li></ul><h4>2. SingleTop</h4><p>If the activity is already at the top of the stack, a new instance is not created. Instead, the existing instance receives the new intent via onNewIntent(). But if there is no activity set as singleTop in the backstack or if it is not a top activity, then the standard flow continues.</p><p>The <strong><em>FLAG_ACTIVITY_SINGLE_TOP</em></strong> flag does the same thing as the singeTop launchMode.</p><ul><li><strong>Definition SingleTop Launch Mode</strong>:</li></ul><pre>&lt;activity<br>    android:name=&quot;.SingleTopActivity&quot;<br>    android:label=&quot;launchMode&quot;<br>    android:launchMode=&quot;singleTop&quot;/&gt;</pre><ul><li><strong>Example</strong>: Clicking on a notification that opens an already opened article in a news app.</li><li><strong>Behavior</strong>: A→B→C→D (if D is already on top, a new instance is not created). A→B→C→D→C (A new instance is created for C because it’s not on top)</li></ul><h4>3. SingleTask</h4><p>If the activity exists in the back stack, it is brought to the top and all activities above it are destroyed. It starts from newIntent. New instance is not created and it is guaranteed to always be the top activity.</p><p>The <strong><em>FLAG_ACTIVITY_NEW_TASK</em></strong> flag does the same thing as SingleTask.</p><ul><li><strong>Definition SingleTask Launch Mode</strong>:</li></ul><pre>&lt;activity<br>    android:name=&quot;.SingleTaskActivity&quot;<br>    android:label=&quot;launchMode&quot;<br>    android:launchMode=&quot;singleTask&quot;/&gt;</pre><ul><li><strong>Example</strong>: An application’s main activity, ensuring only one instance exists.</li><li><strong>Behavior</strong>: A→B→C→D (if C is singleTask, launching it again results in A→B→C).</li></ul><h4>4. SingleInstance</h4><p>Similar to SingleTask, but the activity runs in its own task. No other activities can be launched into this task. No other activities that opened from here are not added to the backstack. They are added the previous back stack. The newly opened task only contains itself.</p><ul><li><strong>Definition SingleInstance Launch Mode</strong>:</li></ul><pre>&lt;activity<br>    android:name=&quot;.SingleInstanceActivity&quot;<br>    android:label=&quot;launchMode&quot;<br>    android:launchMode=&quot;singleInstance&quot; /&gt;</pre><ul><li><strong>Example</strong>: A video call screen, which should be isolated and always have a single screen.</li><li><strong>Behavior</strong>: A→B→C→D, launching singleInstance E results in a new task with E.</li></ul><h4>5. SingleInstancePerTask</h4><p>Like SingleInstance, but a new task is created every time it is launched, and it does not appear in the overview screen.</p><p>The <strong><em>FLAG_ACTIVITY_MULTIPLE_TASK </em></strong>flag does the same thing as SingleInstancePerTask.</p><ul><li><strong>Definition SingleInstancePerTask Launch Mode</strong>:</li></ul><pre>&lt;activity<br>    android:name=&quot;.SingleInstancePerTaskActivity&quot;<br>    android:label=&quot;launchMode&quot;<br>    android:launchMode=&quot;singleInstancePerTask&quot; /&gt;</pre><ul><li><strong>Example</strong>: Situations where an activity should not have multiple instances within the same task but can exist in multiple tasks.</li><li><strong>Behavior</strong>: Each launch creates a new task.</li></ul><p>Understanding and correctly implementing Android launch modes is essential for ensuring a smooth and intuitive user experience. By following these best practices, we can effectively manage activity instances, task relationships, and the back stack behavior to optimize app navigation and performance.</p><h4>Sources</h4><ul><li><a href="https://developer.android.com/guide/components/activities/tasks-and-back-stack">Android Developers: Tasks And Back Stack</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38d837b5726c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter’da Shared Preferences Kullanımı]]></title>
            <link>https://medium.com/@hicranfiliz/flutterda-shared-preferences-kullan%C4%B1m%C4%B1-d9793e4d410e?source=rss-6e0c840bca2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9793e4d410e</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[sharedpreferences]]></category>
            <category><![CDATA[medium]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[local-database]]></category>
            <dc:creator><![CDATA[Hicran Filiz]]></dc:creator>
            <pubDate>Tue, 23 Apr 2024 19:56:13 GMT</pubDate>
            <atom:updated>2024-04-23T19:56:13.561Z</atom:updated>
            <content:encoded><![CDATA[<p>Küçük Verileri Depolamanın Kolay Yolu</p><p>Mobil uygulama geliştirirken, uygulamanın kullanıcı tercihlerini, oturum bilgilerini küçük veriler halinde saklamak gerekebilir. Flutter bu ihtiyacı karşılayan yerel depolama mekanizması olarak kullanılan bir kitaplık sunar: Shared Preferences. Bu yazıda Shared Preferences’ın Flutter uygulamalarında nasıl kullanıldığını anlatacağım.</p><h4>Shared Preferences Nedir?</h4><ul><li>Shared Preferences anahtar-değer (key-value) çiftleri şeklinde veri saklamaya olanak tanıyan bir yöntemdir. Bu kitaplık sayesinde , uygulama kapatılsa bile veriler korunur.</li></ul><h4>Shared Preferences’ın sunduğu temel avantajlar:</h4><ul><li>Kullanıcı Deneyimi: Uygulamayı kullanıcının tercihlerine göre, örneğin tema bilgisi, kullanıcı profili, bildirim ayarları, arama geçmişi gib özelleştirerek daha iyi bir kullanıcı deneyimi sağlar.</li><li>Hızlı Erişim: Küçük veri parçalarına hızlı ve kolay bir şekilde erişim sağlar.</li><li>Kolay Kullanım: Verileri kaydetmek ve bu verileri okumak oldukça basittir.</li><li>Çeşitli Veri Türleri Desteği: String, int, float, boolean gibi temel veri türlerini depolayabilir.</li></ul><h4>Temel Kullanım Alanları:</h4><ul><li>Kullanıcı Ayarlarının Saklanması: Kullanıcı profili , tema tercihi, bildirim ayarları vb.</li><li>Oturum Açma Durumunun Yönetilmesi</li><li>Uygulama İçi Son Durumun Korunması</li></ul><h4>Kurulum</h4><p>Flutter uygulamasında Shared Preferences kullanabilmek için “pubspec.yaml” dosyasına aşağıdaki bağımlılık eklenmelidir. Bu bağımlılığın güncel sürümünü <a href="https://pub.dev/">pub.dev</a> üzerinden bulabilirsiniz.</p><pre>dependencies:<br>  flutter:<br>    sdk: flutter<br>  shared_preferences: ^2.2.2</pre><p>Bu bağımlılığı ekledikten sonra terminalde ‘flutter pub get’ komutu çalıştırılarak proje güncellenir.</p><h4>Shared Preferences ile Veriler Nasıl Saklanır ve Okunur?<br>Veri Saklama:</h4><p>Shared Preferences ile veri saklamak için öncelikle SharedPreferences nesnesi oluşturmalı ve key-value çiftleri kullanarak verileri saklamalıyız. Örnek olarak:</p><pre>final prefs = await SharedPreferences.getInstance();<br> // String deger kaydetme<br>   await prefs.setString(&#39;username&#39;, &#39;flutter&#39;);<br><br>  // Int deger kaydetme<br>   await prefs.setInt(&#39;counter&#39;, 10);<br><br>  // Boolean deger kaydetme<br>   await prefs.setBool(&#39;repeat&#39;, true);<br><br>  // double deger kaydetme<br>   Await prefs.setDouble(‘double’, 3.14)</pre><h4>Veri Okuma:</h4><p>Saklanan verilere Yine SharedPreferences nesnesi üzerinden erişilebilir.</p><pre><br>   final prefs = await SharedPreferences.getInstance();<br><br>  // Int deger okuma<br>   int counter = prefs.getInt(&#39;counter&#39;) ?? 0;<br><br>  // Boolen deger okuma<br>   bool repeat = prefs.getBool(&#39;repeat&#39;) ?? false;<br><br>  // String deger okuma<br>   String username = prefs.getString(&#39;username&#39;) ?? &#39;default_username&#39;;<br><br>  // double deger okuma<br>   double double = prefs.getDouble(&#39;double&#39;) ?? 0.0;</pre><h4>Örnek Uygulama</h4><p>Shared Preferences kullanılan bir basit bir uygulama:</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:shared_preferences/shared_preferences.dart&#39;;<br><br>void main() {<br>  runApp(MyApp());<br>}<br><br>class MyApp extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;SharedPreferences Örneği&#39;,<br>      theme: ThemeData(<br>        primarySwatch: Colors.blue,<br>      ),<br>      home: MyHomePage(),<br>    );<br>  }<br>}<br><br>class MyHomePage extends StatefulWidget {<br>  @override<br>  _MyHomePageState createState() =&gt; _MyHomePageState();<br>}<br><br>class _MyHomePageState extends State&lt;MyHomePage&gt; {<br>  final TextEditingController _nameController = TextEditingController();<br>  String _savedName = &#39;&#39;;<br><br>  @override<br>  void initState() {<br>    super.initState();<br>    _loadName();<br>  }<br><br>  // Adı SharedPreferences&#39;dan yükleyen fonksiyon<br>  void _loadName() async {<br>    final prefs = await SharedPreferences.getInstance();<br>    setState(() {<br>      _savedName = prefs.getString(&#39;name&#39;) ?? &#39;Kaydedilen isim yok&#39;;<br>    });<br>  }<br><br>  // Adı SharedPreferences&#39;a kaydeden fonksiyon<br>  void _saveName() async {<br>    final prefs = await SharedPreferences.getInstance();<br>    prefs.setString(&#39;name&#39;, _nameController.text);<br>    _loadName();<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        title: Text(&#39;SharedPreferences Örneği&#39;),<br>      ),<br>      body: Padding(<br>        padding: const EdgeInsets.all(16.0),<br>        child: Column(<br>          mainAxisAlignment: MainAxisAlignment.center,<br>          children: &lt;Widget&gt;[<br>            TextField(<br>              controller: _nameController,<br>              decoration: InputDecoration(labelText: &#39;İsim giriniz&#39;),<br>            ),<br>            SizedBox(height: 20),<br>            TextButton(onPressed: _saveName, child: Text(&quot;İsmi Kaydet&quot;)),<br>            SizedBox(height: 20),<br>            Text(&#39;Kayıtlı İsim: $_savedName&#39;),<br>          ],<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Uygulama çalışırken:</p><p><a href="https://youtube.com/shorts/A2PTCWTpV3Y?feature=share">sharedpreferences</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9793e4d410e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Activity-LifeCycle]]></title>
            <link>https://medium.com/@hicranfiliz/activity-lifecycle-d974ac83ec09?source=rss-6e0c840bca2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d974ac83ec09</guid>
            <category><![CDATA[lifecycle]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[activity]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Hicran Filiz]]></dc:creator>
            <pubDate>Mon, 24 Oct 2022 20:05:35 GMT</pubDate>
            <atom:updated>2022-10-27T21:28:34.536Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>ACTIVITY</strong></p><p>Activity, uygulamalarımızın ana giriş noktasıdır. Ekranda görünen tüm componentler activity üzerinde bulunur. Ekranı açtığımızda görünen ilk activity ; main activity’dir ve diğer activitylere buradan erişilir.</p><p>Uygulamada kullanılacak activity’leri uygulamanın manifest dosyasında tanımlamamız gerekir.</p><figure><img alt="Manifest dosyasına activity tanımlama" src="https://cdn-images-1.medium.com/max/754/1*I-YB6s11lVBkRv2tV9vqIg.png" /></figure><p>Manifest dosyasına sadece name bilgisi verilmesi yeterlidir. Ama ilk başta gösterilecek activity yani main activity bir intent-filter almalı. İntent-filter bir activity’nin diğer uygulamalar tarafından kullanılabilmesine izin verir.</p><blockquote><strong><em>*Not : </em></strong>Uygulamayı yayımladıktan sonra activity’lerin ismini değiştirmek shortcut problemlerine yol açabilir.</blockquote><p><strong>ACTIVITY LIFECYCLE</strong></p><p>Uygulamada gezinirken activity yaşam döngüsü farklı durumlardan geçer. Bu durumlarda activity’nin hangi işi yapacağını lifecycle fonksiyonlarıyla belirleyebiliriz. Bu fonksiyonları doğru kullanmak uygulamanızı daha performanslı hale getirir ve şu örnek sorunları çözer:</p><p>1.Uygulama kullanılırken arama geldiğinde veya başka bir uygulamaya geçildiğinde uygulamanın çökmesi.</p><p>2.Ekranı portrait(dikey)’den landscape(yatay)’e çevirdiğimizde girilen değişikliklerin kaybolması.</p><p>Bu fonksiyonların neler olduğunu ve fonksiyonlar arası dönüşleri aşağıdaki şemada görebilirsiniz:</p><figure><img alt="Activity yaşam döngüsü.." src="https://cdn-images-1.medium.com/max/523/1*RLsL3GjjUt3djhCK-cOXYA.png" /></figure><ul><li><strong>onCreate():</strong> Sistem activity’yi ayağa kaldırdığı anda bu fonksiyon çalışır. Activity’nin temel bileşenleri burada başlar. Örneğin görünümleri oluşturma işlemleri ve veriyle ilgili işlemler burada yapılır. En önemlisi activity’nin kullanıcı arayüzü (UI) düzenini belirlemesi için gereken setContentView() öğesi burada çağrılmalıdır.</li><li><strong>onStart():</strong> Activity’nin ekranda görülmeye başladığı yerdir.</li><li><strong>onResume(): </strong>Activity’nin focus olduğu, kullanıcının uygulamayla etkileşime girdiği yerdir. Focus kaybolana kadar uygulama Resume’da kalır.</li><li><strong>onPause():</strong> Activity’nin focusunu kaybettiği yer. Bu durum ne zaman oluşur: kullanıcı geri tuşu veya son kullanılanlar tuşuna bastığında, bir arama geldiğinde, popup dialog gösterildiğinde activity onPause’a düşer. Bu durumda uygulama hala kullanıcıya görünür ama çoğu zaman kullanıcının activity’den ayrıldığının göstergesidir ve kısa bir süre sonra uygulama durdurulur (onStop) veya devam ettirilir(onResume).</li><li><strong>onStop():</strong> Activity artık kullanıcıya görünmediğinde sistem onStop metodunu çağırır. onStop’tan sonra activity kullanıcıyla tekrar etkileşime girmek için geri geliyorsa onRestart çalışır. Eğer activity tamamen yok edilmişse onDestroy çalışır.</li><li><strong>onRestart():</strong> Sistem durduruldu durumundan geri tekrar başlatılırsa bu çağrılır.</li><li><strong>onDestroy():</strong> Bu fonksiyon uygulamanın kullandığı son fonksiyondur. Bir activity tamamen yok edildiğinde onun sistem kaynaklarının boşaltılması için çağrılır.</li></ul><blockquote><strong><em>*Not : </em></strong>Lifecycle problemi yaşamamak için şemadaki dönüşlerde gösterildiği gibi;</blockquote><blockquote>Pause’da yaptığımız işlemlerin tersini Resume’da</blockquote><blockquote>Stop’da yaptığımız işlemlerin tersini Start’ta yapmalıyız.</blockquote><blockquote><strong><em>*Not : </em></strong>Lifecycle fonksiyonlarının yeri ve sırası önemli değil.</blockquote><blockquote><strong><em>*Not : </em></strong>Ekranı portrait ‘ten landscape ‘ e çevirdiğimizde yaşanan problem (Configuration change problemi) onSaveInstanceState ve onRestoreInstanceState metodlarıyla çözülür.</blockquote><blockquote>SaveInstanceState -&gt; Ekranda değişebilen tüm alanların verileri Bundle içine konulur.</blockquote><blockquote>RestoreInstanceState -&gt; Veriler geri alınır.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d974ac83ec09" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>