Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Practical Implementation of Up Navigation
Search
Keisuke Kobayashi
March 22, 2017
Programming
2k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Practical Implementation of Up Navigation
potatotips #38
Keisuke Kobayashi
March 22, 2017
More Decks by Keisuke Kobayashi
See All by Keisuke Kobayashi
AI 1st でエンタープライズ SaaS を立ち上げる / AI 1st Enterprise SaaS
kobakei
1
270
プロダクト開発をAI 1stに変革する〜SaaS is dead時代で生き残るために〜 / AI 1st Product Development
kobakei
0
2.8k
今日から始める依存性の注入 / First Time Dependency Injection
kobakei
26
7.8k
iOSアプリの技術的負債をどう返済したか / How to repay the technical debt of iOS app
kobakei
2
1k
iOSアプリ内で不正なSSL証明書を検知する / SSL Pinning for iOS apps
kobakei
34
12k
Kyashアプリ開発の現場
kobakei
4
3k
Review of Google I/O 2017 & Prepare for Google I/O 2018
kobakei
0
350
APIクライアントをCodableで置き換えた話
kobakei
0
1.6k
開発者が知っておきたい通知の歴史
kobakei
9
7.9k
Other Decks in Programming
See All in Programming
継続モナドとリアクティブプログラミング
yukikurage
3
620
AIが無かった頃の素敵な出会いの話
codmoninc
1
130
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
2.8k
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
220
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
170
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
260
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
510
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
390
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.5k
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
140
Claude Team Plan導入・ガイド
tk3fftk
0
220
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
GitHub's CSS Performance
jonrohan
1033
470k
A Soul's Torment
seathinner
6
3.1k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
350
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
ラッコキーワード サービス紹介資料
rakko
1
4M
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
400
The agentic SEO stack - context over prompts
schlessera
0
850
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
Transcript
Practical Implementation of Up Navigation Keisuke Kobayashi (@kobakei) potatotips #38
About me • Keisuke Kobayashi • Coubic Inc • GitHub,
Qiita: @kobakei • Twitter: @ksk_kbys • Android, Rails, React
Up Navigation?
Up Back
Back vs Up • Back • Navigate to previous screen
which may be other app • Up • Navigate to parent screen in same app
Example
EC app • Timeline > Detail • Timeline > Search
> Detail • Timeline > Detail > Detail • Recommendation, similar items, … • Deep link > Detail • Notification, Google search result, …
Navigation Flow 5JNFMJOF 4FBSDI %FUBJM (deep link)
Navigation Flow 5JNFMJOF 4FBSDI %FUBJM (deep link) From search
Navigation Flow 5JNFMJOF 4FBSDI %FUBJM (deep link) Otherwise From search
How to implement?
Just calling Activity#finish() ?
Calling Activity#finish() ? @Override public boolean onOptionsItemSelected(MenuItem item) { switch
(item.getItemId()) { case android.R.id.home: finish(); return true; } return super.onOptionsItemSelected(item); }
Calling Activity#finish() ? • May be OK in simple flow
• NG in Timeline > Detail > Detail flow • It opens previous Detail screen… • NG in deep link flow • It closes app…
OK, I will copy & paste from developer.android.com
developer.android.com @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) {
// Respond to the action bar's Up/Home button case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); }
Something wrong…
What is wrong? 1. Recreated parent activity • Scroll position,
bottom navigation etc 2. Always same parent activity regardless of where it comes from
What is wrong? 1. Recreated parent activity • Scroll position,
bottom navigation etc 2. Always same parent activity regardless of where it comes from
Avoid recreating parent @Override public boolean onOptionsItemSelected(MenuItem item) { switch
(item.getItemId()) { case android.R.id.home: Intent upIntent = NavUtils.getParentActivityIntent(this); upIntent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(upIntent); finish(); return true; } return super.onOptionsItemSelected(item); }
What is wrong? 1. Recreated parent activity • Scroll position,
bottom navigation etc 2. Always same parent activity regardless of where it comes from
Set parent activity class to bundle extra // DetailActivity#createIntent public
static Intent createIntent( @NonNull Context context, @Nullable Class<? extends Activity> parentClass) { Intent intent = new Intent(context, DetailActivity.class); if (parentClass != null) { intent.putExtra(KEY_PARENT, parentClass.getName()); } return intent; }
Restore parent activity class from bundle extra // Parent activity
class private Class parentClass; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // … String parentClassName = getIntent().getStringExtra(KEY_PARENT); if (TextUtils.isEmpty(parentClassName)) { parentClass = MainActivity.class; } else { try { parentClass = Class.forName(parentClassName); } catch (ClassNotFoundException e) { Timber.e(e); } } }
Create up intent with parent activity class @Override public
boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Intent upIntent = new Intent(getApplicationContext(), parentClass); upIntent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(upIntent); finish(); return true; } return super.onOptionsItemSelected(item); }
Complete
Conclusion • Explained how to implement UP navigation in complex
flow • Key points • FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGE_TOP • Set parent class in bundle extra and use for Intent to parent activity
Appendix • ͪΐͬͱෳࡶͳUPϘλϯͷ࣮ in Qiita • http://qiita.com/kobakei/items/ ae1a6d2062f34d3f6771 • DroidKaigi
2017 app
Thanks!