{"id":24935,"date":"2021-07-15T09:00:14","date_gmt":"2021-07-15T00:00:14","guid":{"rendered":"https:\/\/mole-kingdom.com\/wpbl\/?p=24935"},"modified":"2021-07-05T16:27:49","modified_gmt":"2021-07-05T07:27:49","slug":"%e3%80%8eandroid-kotlin-fundamentals%e3%80%8f%e3%82%92%e3%82%84%e3%81%a3%e3%81%9f4","status":"publish","type":"post","link":"https:\/\/mole-kingdom.com\/wpbl\/2021\/07\/15\/24935.html","title":{"rendered":"\u300eAndroid Kotlin Fundamentals\u300f\u3092\u3084\u3063\u305f(4)"},"content":{"rendered":"<h1>Android Kotlin Fundamentals: Lifecycles and logging<\/h1>\n<h2>3. Explore the lifecycle methods and add basic logging<\/h2>\n<h3>Step 1: Examine the onCreate() method and add logging<\/h3>\n<p>\u9805\u756a6\u304c\u6539\u884c\u3055\u308c\u3066\u3044\u306a\u3044\u3002<\/p>\n<hr width=\"90%\">\n<h2>4. Use Timber for logging<\/h2>\n<h3>Step 2: Create an Application class and initialize Timber<\/h3>\n<blockquote><p>Warning: It might be tempting to add your own code to the Application class, because the class is created before all of your activities and can hold global state. But just as it's error-prone to make readable and writable static variables that are globally available, it's easy to abuse the Application class. Avoid putting any activity code in the Application class unless the code is really needed.<\/p><\/blockquote>\n<p>\u3075\u30fc\u3080\u3001Application\u30af\u30e9\u30b9\u306b\u306f\u4f59\u8a08\u306a\u30b3\u30fc\u30c9\u3092\u66f8\u304b\u306a\u3044\u306e\u304c\u304a\u4f5c\u6cd5\u306a\u306e\u306d(\u00b4\uff65\u03c9\uff65\uff40)<\/p>\n<hr width=\"90%\">\n<h2>5. Explore lifecycle use cases<\/h2>\n<h3>Use case 3: Partially hide the activity<\/h3>\n<blockquote><p>Whatever code runs in onPause() blocks other things from displaying, so keep the code in onPause() lightweight.<\/p><\/blockquote>\n<p>onPause()\u5185\u306f\u8efd\u3081\u306b\u2026\u03c6(\uff65\u03c9\uff65\uff40 )\uff92\uff93\uff92\uff93\u2026<\/p>\n<hr width=\"90%\">\n<h2>6. Explore the fragment lifecycle<\/h2>\n<p>Lifecycles and logging\u306e\u5f8c\u306f\u6b21\u306eComplex Lifecycle Situations\u3078\u306e\u30ea\u30f3\u30af\u304c\u306a\u3044\uff1f<\/p>\n<hr>\n<h1>Android Kotlin Fundamentals: Complex Lifecycle Situations<\/h1>\n<h2>4. Task: Use the Android lifecycle library<\/h2>\n<h3>Step 1: Turn DessertTimer into a LifecycleObserver<\/h3>\n<p>LifecycleOwner\u3092implement\u3057\u3066\u308b\u306e\u306fFragmentActivity\u306esuperclass\u306e<a href=\"https:\/\/androidx.tech\/artifacts\/core\/core\/1.0.2-source\/androidx\/core\/app\/ComponentActivity.java.html\" rel=\"noopener\" target=\"_blank\">ComponentActivity<\/a>\u3067\u306f\u306a\u304b\u308d\u3046\u304b\u2026<\/p>\n<hr width=\"90%\">\n<h2>5. Task: Simulate app shutdown and use onSaveInstanceState()<\/h2>\n<h3>Step 1: Use adb to simulate a process shutdown<\/h3>\n<blockquote><p>The Android Debug Bridge (adb) is a command-line tool that lets you send instructions to emulators and devices attached to your computer. <\/p><\/blockquote>\n<p>Android Debug Bridge(adb)\u306f\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u306b\u63a5\u7d9a\u3055\u308c\u305f\u30c7\u30d0\u30a4\u30b9\u307e\u305f\u306f\u30a8\u30df\u30e5\u30ec\u30fc\u30bf\u3078\u6307\u793a\u3092\u9001\u308b\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u30c4\u30fc\u30eb\u3068\u2026\u03c6(\uff65\u03c9\uff65\uff40 )\uff92\uff93\uff92\uff93\u2026<\/p>\n<p><span class=\"os\">4.Type adb and press Return.<\/span><br \/>\n\u4eca\u3082\u5411\u3053\u3046\u3067\u306f\u30a8\u30f3\u30bf\u30fc\u3058\u3083\u306a\u304f\u3066\u30ea\u30bf\u30fc\u30f3\u30ad\u30fc\u547c\u3073\u304c\u4e3b\u6d41\u306a\u3093\u3060\u308d\u3046\u304b\u3002<\/p>\n<p>\u3093\u30fc\u3001<br \/>\n<span class=\"os\">adb shell am kill com.example.android.dessertclicker<\/span><br \/>\n\u304c\u4e0a\u624b\u304f\u52d5\u3044\u3066\u306a\u3044\u306e\u304b\u3001Recents Screen\u304b\u3089\u5fa9\u5e30(?)\u3055\u305b\u3066\u3082\u3001\u524d\u306e\u72b6\u614b\u304c\u6b8b\u3063\u3066\u308b\u306a\u2026<br \/>\n\u4f55\u304b\u9593\u9055\u3063\u3066\u308b\u306a(\uff89\u2200`)<\/p>\n<blockquote><p>adb server version (41) doesn't match this client (40); killing...<br \/>\ncould not read ok from ADB Server<br \/>\n* failed to start daemon<br \/>\nerror: cannot connect to daemon<\/p><\/blockquote>\n<p>\u3063\u3066\u51fa\u3066\u308b\u3051\u3069\u3001\u3053\u308c\u306f\u554f\u984c\u3042\u308b\u306e\u304b\u306a\u3044\u306e\u304b\u304c\u307e\u305a\u308f\u304b\u3089\u3093(\u30fb\u2200\u30fb)<\/p>\n<p>\u30b3\u30de\u30f3\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u3067\u4e0a\u306e\u30b3\u30de\u30f3\u30c9\u3092\u653e\u3063\u305f\u3089\u3001\u4f55\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3082\u51fa\u3055\u305a\u306b\u7d42\u4e86\u51fa\u6765\u305f\u6a21\u69d8\u3002Recents Screen\u304b\u3089\u5fa9\u5e30\u3055\u305b\u305f\u3089\u3001\u7121\u4e8b\u306b\u524d\u306e\u72b6\u614b\u304c\u30ea\u30bb\u30c3\u30c8\u3055\u308c\u3066\u3044\u305f\u3002<\/p>\n<p>\u306a\u3093\u3067AS\u3060\u3068\u4e0a\u624b\u304f\u884c\u304b\u306a\u3044\u3093\u3060\u308d\u3046\u3068\u60a9\u3093\u3060\u304c\u3001\u4e00\u56de\u30b3\u30de\u30f3\u30c9\u30d7\u30ed\u30f3\u30c8\u5074\u3067\u4e0a\u624b\u304f\u884c\u3063\u305f\u3089\u3001AS\u3067\u3082\u4e0a\u624b\u304f\u884c\u304f\u3088\u3046\u306b\u306a\u3063\u305f\u3002\u539f\u56e0\u306f\u3088\u304f\u308f\u304b\u3089\u306a\u3044\u304c\u3001\u53d6\u308a\u6562\u3048\u305a\u89e3\u6c7a\u3057\u305f\u304b\u3089\u3044\u3044\u304b(\uff89\u2200`)<br \/>\nadb.exe\u304c\u8907\u6570\u8d77\u52d5\u3057\u3066\u305f\u3093\u304b\u306a\uff1f<\/p>\n<h3>Step 2: Use onSaveInstanceState() to save bundle data<\/h3>\n<blockquote><p>A bundle is a collection of key-value pairs, where the keys are always strings.<\/p><\/blockquote>\n<p>\u524d\u306b\u3082\u8aac\u660e\u304c\u3042\u3063\u305f\u304c\u3001\u30ad\u30fc\u306f\u5fc5\u305a\u6587\u5b57\u5217\u306a\u3093\u3060\u306d\u3047\u3002<\/p>\n<blockquote><p>Generally you should store far less than 100k, otherwise you risk crashing your app with the TransactionTooLargeException error.<\/p><\/blockquote>\n<p>\u30b5\u30a4\u30ba\u306f100KB\u4ee5\u4e0b\u306b\u6291\u3048\u306a\u3044\u3068\u99c4\u76ee\u3068\u2026\u03c6(\uff65\u03c9\uff65\uff40 )\uff92\uff93\uff92\uff93\u2026<\/p>\n<p><span class=\"os\">The putInt() method (and similar methods from the Bundle class like putFloat() and putString() takes two arguments:<\/span><br \/>\nputString()\u306e\u5f8c\u306b\u9589\u3058\u62ec\u5f27\u304c\u629c\u3051\u3066\u308b\uff1f<\/p>\n<h3>Step 3: Use onCreate() to restore bundle data<\/h3>\n<blockquote><p>So if the bundle is not null, you know you're \"re-creating\" the activity from a previously known point.<\/p><\/blockquote>\n<p>\u305d\u308c\u3067\u5224\u5b9a\u304c\u51fa\u6765\u308b\u308f\u3051\u304b\u3002<\/p>\n<p>which in turn<br \/>\n<a href=\"https:\/\/dreamcometrue358.com\/which-in-turn\/\" rel=\"noopener\" target=\"_blank\">which in turn\u3063\u3066\u4f55\uff1f\u975e\u5236\u9650\u7528\u6cd5\uff08\u4ed8\u52a0\u7528\u6cd5\uff09\u3063\u3066\uff1f<\/a><br \/>\n<a href=\"https:\/\/jobcatalog.yahoo.co.jp\/qa\/list\/14169084854\/\" rel=\"noopener\" target=\"_blank\">\u300cwhich in turn,\u300d\u306e\u8a33\u3057\u65b9\u306b\u3064\u3044\u3066 \u4e0b\u8a18\u306e\u6587\u7ae0\u3067\u300cwhich in turn,\u300d\u306f\u3069\u3046\u8a33\u305b\u3070\u826f\u3044\u3067\u3057\u2026<\/a><\/p>\n<hr>\n<p>\u3088\u3046\u3084\u3063\u3068\u3053\u3053\u307e\u3067\u3067Lesson4\u304c\u7d42\u308f\u3063\u305f\u2026(\u30fd'\u03c9&#096;)<br \/>\n\u52c9\u5f37\u306b\u306a\u308b\u3051\u3069\u9577\u3044\u306a\uff57<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android Kotlin Fundamentals: Lifecycles and logging 3. Explore the lifecycle methods and add basic logging Ste...  <a class=\"excerpt-read-more\" href=\"https:\/\/mole-kingdom.com\/wpbl\/2021\/07\/15\/24935.html\" title=\"Read \u300eAndroid Kotlin Fundamentals\u300f\u3092\u3084\u3063\u305f(4)\">\u3082\u3063\u3068\u8aad\u3080 &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[18,101,113,124,95],"tags":[],"class_list":["post-24935","post","type-post","status-publish","format-standard","hentry","category-android","category-android-studio","category-google","category-kotlin","category-impressions"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2pLuj-6ub","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":24934,"url":"https:\/\/mole-kingdom.com\/wpbl\/2021\/07\/12\/24934.html","url_meta":{"origin":24935,"position":0},"title":"\u300eAndroid Kotlin Fundamentals\u300f\u3092\u3084\u3063\u305f(3)","author":"moleking","date":"2021\u5e747\u670812\u65e5","format":false,"excerpt":"Android Kotlin Fundamentals 02.4:Data binding basi\u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24927,"url":"https:\/\/mole-kingdom.com\/wpbl\/2021\/07\/06\/24927.html","url_meta":{"origin":24935,"position":1},"title":"\u300eAndroid Kotlin Fundamentals\u300f\u3092\u3084\u3063\u305f(1)","author":"moleking","date":"2021\u5e747\u67086\u65e5","format":false,"excerpt":"Android Kotlin \u306e\u57fa\u790e\u306e\u305f\u3081\u306e Codelab \u3068\u8a00\u3044\u3064\u3064\u3001\u307e\u3060\u9014\u4e2d(\uff89\u2200`) \u307e\u3060L\u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24932,"url":"https:\/\/mole-kingdom.com\/wpbl\/2021\/07\/09\/24932.html","url_meta":{"origin":24935,"position":2},"title":"\u300eAndroid Kotlin Fundamentals\u300f\u3092\u3084\u3063\u305f(2)","author":"moleking","date":"2021\u5e747\u67089\u65e5","format":false,"excerpt":"Android Kotlin Fundamentals: Add user interactivit\u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24858,"url":"https:\/\/mole-kingdom.com\/wpbl\/2021\/06\/23\/24858.html","url_meta":{"origin":24935,"position":3},"title":"\u300eWelcome to Android Basics in Kotlin\u300f\u3092\u3084\u3063\u305f(\u7d42)","author":"moleking","date":"2021\u5e746\u670823\u65e5","format":false,"excerpt":"\u30d5\u30e9\u30b0\u30e1\u30f3\u30c8\u9593\u306e\u5171\u6709 ViewModel 4. \u5171\u6709 ViewModel \u3092\u4f5c\u6210\u3059\u308b OrderVi\u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":12809,"url":"https:\/\/mole-kingdom.com\/wpbl\/2015\/08\/06\/12809.html","url_meta":{"origin":24935,"position":4},"title":"Neko Astume (Collect cats) \u2013 Goods list [ Food &#038; etc]","author":"moleking","date":"2015\u5e748\u67086\u65e5","format":false,"excerpt":"* Help and other links are here. * This entry may \u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mole-kingdom.com\/wpbl\/wp-content\/uploads\/2015\/08\/goods-funamori.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":24848,"url":"https:\/\/mole-kingdom.com\/wpbl\/2021\/06\/17\/24848.html","url_meta":{"origin":24935,"position":5},"title":"\u300eWelcome to Android Basics in Kotlin\u300f\u3092\u3084\u3063\u305f(2)","author":"moleking","date":"2021\u5e746\u670817\u65e5","format":false,"excerpt":"Layouts Kotlin\u306e\u30af\u30e9\u30b9\u3068\u7d99\u627f 2. \u30af\u30e9\u30b9\u968e\u5c64\u3068\u306f \u4e00\u5fdc\u3001\"\u8c46\u985e\"\u306e\u3068\u3053\u308d\u306e\u30ea\u30f3\u30af\u304ch\u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/posts\/24935","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/comments?post=24935"}],"version-history":[{"count":1,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/posts\/24935\/revisions"}],"predecessor-version":[{"id":24947,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/posts\/24935\/revisions\/24947"}],"wp:attachment":[{"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/media?parent=24935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/categories?post=24935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/tags?post=24935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}