{"id":19625973,"url":"https://github.com/leoando/android13-back-gesture-samples","last_synced_at":"2025-08-25T13:07:44.639Z","repository":{"id":102995384,"uuid":"570778055","full_name":"LeoAndo/android13-back-gesture-samples","owner":"LeoAndo","description":"Sample for Back Gesture (Android 13+)","archived":false,"fork":false,"pushed_at":"2024-11-21T02:04:31.000Z","size":29787,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-09T12:38:49.553Z","etag":null,"topics":["android-java","android13","android14","predictive-back-gesture"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LeoAndo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"LeoAndo"}},"created_at":"2022-11-26T04:59:29.000Z","updated_at":"2024-11-21T02:04:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"8d31ff34-99e5-4d82-b173-89dd16338ba9","html_url":"https://github.com/LeoAndo/android13-back-gesture-samples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeoAndo%2Fandroid13-back-gesture-samples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeoAndo%2Fandroid13-back-gesture-samples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeoAndo%2Fandroid13-back-gesture-samples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeoAndo%2Fandroid13-back-gesture-samples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LeoAndo","download_url":"https://codeload.github.com/LeoAndo/android13-back-gesture-samples/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240926397,"owners_count":19879737,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android-java","android13","android14","predictive-back-gesture"],"created_at":"2024-11-11T11:44:21.978Z","updated_at":"2025-02-26T20:12:43.255Z","avatar_url":"https://github.com/LeoAndo.png","language":"Java","funding_links":["https://github.com/sponsors/LeoAndo"],"categories":[],"sub_categories":[],"readme":"# 開発環境\nAndroid Studio Iguana\n\n# android13-back-gesture-samples\nSample for Back Gesture (Android 13+)\n\n# 開発メモ\n\nOS13で、戻るジェスチャーを使いたい場合は開発者オプションの設定が必要。\u003cbr\u003e\n詳しくは、[ここ](https://developer.android.com/guide/navigation/predictive-back-gesture#dev-option)参照する。\u003cbr\u003e\nそれより古いOSは戻るジェスチャーは使えない。Jetpack API側で従来のキーイベント処理を行ってくれる。\u003cbr\u003e\n\n\u003cimg width=\"739\" alt=\"スクリーンショット 2022-11-26 20 43 04\" src=\"https://user-images.githubusercontent.com/16476224/204086962-35b7529b-363b-487c-8009-734787c80961.png\"\u003e\n\nLifecycleOwnerを引数に取る[OnBackPressedDispatcher#addCallback](https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcher#addCallback(androidx.lifecycle.LifecycleOwner,androidx.activity.OnBackPressedCallback))を使用すれば、画面のライフサイクルの終了タイミングで解放処理を行ってくれるのでメモリリークを防げる。\n\nhttps://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/OnBackPressedDispatcher.java;l=313?q=OnBackPressedDispatcher\u0026ss=androidx%2Fplatform%2Fframeworks%2Fsupport\u0026hl=ja\n```java\n       @Override\n        public void cancel() {\n            mLifecycle.removeObserver(this);\n            mOnBackPressedCallback.removeCancellable(this);\n            if (mCurrentCancellable != null) {\n                mCurrentCancellable.cancel();\n                mCurrentCancellable = null;\n            }\n        }\n```\n\n\nJetpack Composeの場合は、`BackHandler`を使う。こちらに関しては、`com.google.accompanist.web.WebView`を使用していれば内部で`BackHandler`を使っているので、開発者が対応する必要はない。\nhttps://github.com/google/accompanist/blob/7a293b358c293d398a9b95185b41ef3cc1136475/web/src/main/java/com/google/accompanist/web/WebView.kt#L84:L86\n```kotlin\n    BackHandler(captureBackPresses \u0026\u0026 navigator.canGoBack) {\n        webView?.goBack()\n    }\n```\n\n`com.google.accompanist.web.WebView`の使い方は以下のサンプルコードを参考にする。\u003cbr\u003e\nhttps://github.com/google/accompanist/blob/a0ebf63b2bb5d681fd5c2c6bb6c2e97022b1b296/sample/src/main/java/com/google/accompanist/sample/webview/BasicWebViewSample.kt\n\n# Capture OS: 13\n\n| バックキー | 戻るジェスチャー |\n|:---|:---:|\n|\u003cimg src=\"https://github.com/LeoAndo/android13-back-gesture-samples/blob/main/JavaSample/capture/android_API33_key_back.gif\" width=320 /\u003e |\u003cimg src=\"https://github.com/LeoAndo/android13-back-gesture-samples/blob/main/JavaSample/capture/android_API33_gesture_back.gif\" width=320 /\u003e |\n\n# Capture OS: 8\n\n| バックキー | 戻るジェスチャー |\n|:---|:---:|\n|\u003cimg src=\"https://github.com/LeoAndo/android13-back-gesture-samples/blob/main/JavaSample/capture/android_API26_key_back.gif\" width=320 /\u003e | 利用不可能 |\n\n\n\n\n\n# refs\nhttps://github.com/LeoAndo/development-conference-memo/issues/161\u003cbr\u003e\nhttps://github.com/LeoAndo/development-conference-memo/issues/81\u003cbr\u003e\nhttps://developer.android.com/guide/navigation/predictive-back-gesture?hl=ja\u003cbr\u003e\nhttps://codelabs.developers.google.com/handling-gesture-back-navigation?hl=ja#0\u003cbr\u003e\n[Jetpack ComposeのBackHandlerを使ったサンプル](https://github.com/raheemadamboev/predictive-back-gesture)\u003cbr\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleoando%2Fandroid13-back-gesture-samples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleoando%2Fandroid13-back-gesture-samples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleoando%2Fandroid13-back-gesture-samples/lists"}