{"id":37181,"date":"2024-11-01T09:55:33","date_gmt":"2024-11-01T09:55:33","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37181"},"modified":"2024-11-01T11:36:19","modified_gmt":"2024-11-01T11:36:19","slug":"java-android-app-development-course-activity-lifecycle","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37181\/","title":{"rendered":"Java Android App Development Course, Activity Lifecycle"},"content":{"rendered":"<p><body><\/p>\n<p>One of the most important concepts in Android app development is the <strong>Activity<\/strong> and its lifecycle. An Activity is a component that makes up the user interface (UI) and represents a screen that users interact with. In this course, we will explore the Activity lifecycle in Android app development using Java and explain the tasks that can be performed at each stage.<\/p>\n<h2>What is an Activity?<\/h2>\n<p>An Activity is a component that represents the user interface of an Android application and corresponds to a single screen within the app. Everything that the user interacts with in the app happens within an Activity. Activities include various UI elements to display information to the user and handle user interactions.<\/p>\n<h2>Activity Lifecycle<\/h2>\n<p>The Activity lifecycle refers to the flow of states and transitions from the creation to the destruction of an Activity. The Android system manages the Activity lifecycle, with the following key methods:<\/p>\n<ul>\n<li><code>onCreate()<\/code><\/li>\n<li><code>onStart()<\/code><\/li>\n<li><code>onResume()<\/code><\/li>\n<li><code>onPause()<\/code><\/li>\n<li><code>onStop()<\/code><\/li>\n<li><code>onDestroy()<\/code><\/li>\n<li><code>onRestart()<\/code><\/li>\n<\/ul>\n<h3>1. onCreate()<\/h3>\n<p>The <code>onCreate()<\/code> method is called when the Activity is first created. It primarily performs UI setup and basic initialization tasks. In this method, the layout is set and initial variables are defined.<\/p>\n<pre><code>public class MainActivity extends AppCompatActivity {\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n    }\n}\n<\/code><\/pre>\n<h3>2. onStart()<\/h3>\n<p>The <code>onStart()<\/code> method is called just before the Activity becomes visible to the user. In this method, the UI can be initialized, signaling that the Activity is ready for user interaction.<\/p>\n<pre><code>@Override\nprotected void onStart() {\n    super.onStart();\n    \/\/ Handle just before the Activity is shown to the user\n}\n<\/code><\/pre>\n<h3>3. onResume()<\/h3>\n<p>The <code>onResume()<\/code> method is called when the Activity is about to become the foreground activity. Common tasks performed here include updating the UI or starting animations.<\/p>\n<pre><code>@Override\nprotected void onResume() {\n    super.onResume();\n    \/\/ Update UI or start animations\n}\n<\/code><\/pre>\n<h3>4. onPause()<\/h3>\n<p>The <code>onPause()<\/code> method is called when another Activity is starting or this Activity is being paused. In this method, data should be saved, or animations should be stopped. It indicates that the user is no longer actively using this Activity.<\/p>\n<pre><code>@Override\nprotected void onPause() {\n    super.onPause();\n    \/\/ Save data and stop animations\n}\n<\/code><\/pre>\n<h3>5. onStop()<\/h3>\n<p>The <code>onStop()<\/code> method is called when the Activity is no longer visible to the user. At this stage, resources should be released, and tasks that need to be handled when the Activity is not visible should be performed.<\/p>\n<pre><code>@Override\nprotected void onStop() {\n    super.onStop();\n    \/\/ Release resources and perform cleanup\n}\n<\/code><\/pre>\n<h3>6. onDestroy()<\/h3>\n<p>The <code>onDestroy()<\/code> method is called when the Activity is finishing. In this method, memory can be released and final cleanup tasks can be carried out. However, this method may not be called, so it is advisable to save important data in <code>onPause()<\/code> or <code>onStop()<\/code>.<\/p>\n<pre><code>@Override\nprotected void onDestroy() {\n    super.onDestroy();\n    \/\/ Final cleanup tasks\n}\n<\/code><\/pre>\n<h3>7. onRestart()<\/h3>\n<p>The <code>onRestart()<\/code> method is called when the Activity is being restarted after stopping. This method is called after <code>onStop()<\/code>. Here, tasks to restore the previous state are performed.<\/p>\n<pre><code>@Override\nprotected void onRestart() {\n    super.onRestart();\n    \/\/ Tasks when restarting the Activity\n}\n<\/code><\/pre>\n<h2>Lifecycle Example<\/h2>\n<p>Now, let&#8217;s create an example that incorporates the Activity lifecycle explained earlier. In this example, we will log the Activity&#8217;s state through button clicks.<\/p>\n<pre><code>import android.os.Bundle;\nimport android.util.Log;\nimport android.view.View;\nimport android.widget.Button;\nimport androidx.appcompat.app.AppCompatActivity;\n\npublic class MainActivity extends AppCompatActivity {\n    private static final String TAG = \"MainActivity\";\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n\n        Button button = findViewById(R.id.button);\n        button.setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View v) {\n                Log.d(TAG, \"Button clicked!\");\n            }\n        });\n    }\n\n    @Override\n    protected void onStart() {\n        super.onStart();\n        Log.d(TAG, \"onStart called\");\n    }\n\n    @Override\n    protected void onResume() {\n        super.onResume();\n        Log.d(TAG, \"onResume called\");\n    }\n\n    @Override\n    protected void onPause() {\n        super.onPause();\n        Log.d(TAG, \"onPause called\");\n    }\n\n    @Override\n    protected void onStop() {\n        super.onStop();\n        Log.d(TAG, \"onStop called\");\n    }\n\n    @Override\n    protected void onDestroy() {\n        super.onDestroy();\n        Log.d(TAG, \"onDestroy called\");\n    }\n}\n<\/code><\/pre>\n<h2>Managing the Lifecycle<\/h2>\n<p>Managing the Activity lifecycle has a significant impact on the performance of the app and the user experience. Data that is necessary during the creation and destruction process should be saved in <code>onPause()<\/code> or <code>onStop()<\/code>, and the UI should be updated in <code>onResume()<\/code> when changes occur.<\/p>\n<h3>Saving State<\/h3>\n<p>When an Activity is restarted after being stopped, it may be necessary to save its state. You can use the <code>onSaveInstanceState()<\/code> method for this purpose. Below is an example of how to save state.<\/p>\n<pre><code>@Override\nprotected void onSaveInstanceState(Bundle outState) {\n    super.onSaveInstanceState(outState);\n    outState.putString(\"key\", \"value\");\n}\n<\/code><\/pre>\n<p>Saved state can be restored in <code>onCreate()<\/code> or <code>onRestoreInstanceState()<\/code>.<\/p>\n<pre><code>@Override\nprotected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.activity_main);\n    \n    if (savedInstanceState != null) {\n        String value = savedInstanceState.getString(\"key\");\n    }\n}\n<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>The Android Activity lifecycle is one of the fundamental components of an app, and understanding it and managing it effectively is important. Performing tasks correctly according to each stage of the lifecycle can provide a better user experience. I hope this course provides you with a basic understanding of the Activity lifecycle.<\/p>\n<p>In conclusion, I have explained the Activity lifecycle in Android app development using Java. Deepen your understanding through practical exercises, and make good use of the lifecycle in various situations!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the most important concepts in Android app development is the Activity and its lifecycle. An Activity is a component that makes up the user interface (UI) and represents a screen that users interact with. In this course, we will explore the Activity lifecycle in Android app development using Java and explain the tasks &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37181\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Java Android App Development Course, Activity Lifecycle&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[137],"tags":[],"class_list":["post-37181","post","type-post","status-publish","format-standard","hentry","category-java-android-app-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java Android App Development Course, Activity Lifecycle - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/37181\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Android App Development Course, Activity Lifecycle - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"One of the most important concepts in Android app development is the Activity and its lifecycle. An Activity is a component that makes up the user interface (UI) and represents a screen that users interact with. In this course, we will explore the Activity lifecycle in Android app development using Java and explain the tasks &hellip; \ub354 \ubcf4\uae30 &quot;Java Android App Development Course, Activity Lifecycle&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37181\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:55:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:36:19+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/37181\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37181\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Java Android App Development Course, Activity Lifecycle\",\"datePublished\":\"2024-11-01T09:55:33+00:00\",\"dateModified\":\"2024-11-01T11:36:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37181\/\"},\"wordCount\":593,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Java Android app development\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37181\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37181\/\",\"name\":\"Java Android App Development Course, Activity Lifecycle - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:55:33+00:00\",\"dateModified\":\"2024-11-01T11:36:19+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37181\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37181\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37181\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Android App Development Course, Activity Lifecycle\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Android App Development Course, Activity Lifecycle - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/37181\/","og_locale":"ko_KR","og_type":"article","og_title":"Java Android App Development Course, Activity Lifecycle - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"One of the most important concepts in Android app development is the Activity and its lifecycle. An Activity is a component that makes up the user interface (UI) and represents a screen that users interact with. In this course, we will explore the Activity lifecycle in Android app development using Java and explain the tasks &hellip; \ub354 \ubcf4\uae30 \"Java Android App Development Course, Activity Lifecycle\"","og_url":"https:\/\/atmokpo.com\/w\/37181\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:55:33+00:00","article_modified_time":"2024-11-01T11:36:19+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/37181\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37181\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Java Android App Development Course, Activity Lifecycle","datePublished":"2024-11-01T09:55:33+00:00","dateModified":"2024-11-01T11:36:19+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37181\/"},"wordCount":593,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Java Android app development"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37181\/","url":"https:\/\/atmokpo.com\/w\/37181\/","name":"Java Android App Development Course, Activity Lifecycle - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:55:33+00:00","dateModified":"2024-11-01T11:36:19+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37181\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37181\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37181\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Java Android App Development Course, Activity Lifecycle"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=37181"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37181\/revisions"}],"predecessor-version":[{"id":37182,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37181\/revisions\/37182"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}