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
230
プロダクト開発をAI 1stに変革する〜SaaS is dead時代で生き残るために〜 / AI 1st Product Development
kobakei
0
2.7k
今日から始める依存性の注入 / First Time Dependency Injection
kobakei
26
7.7k
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
Vite+ Unified Toolchain for the Web
naokihaba
0
190
AIとRubyの静的型付け
ukin0k0
0
560
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
190
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.9k
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
250
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
110
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
100
Webフレームワークの ベンチマークについて
yusukebe
0
150
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.3k
TAKTでAI駆動開発の品質を設計する
j5ik2o
6
1.1k
AIで効率化できた業務・日常
ochtum
0
120
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
1
640
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.6k
The untapped power of vector embeddings
frankvandijk
2
1.7k
The Language of Interfaces
destraynor
162
27k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Claude Code のすすめ
schroneko
67
230k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
Discover your Explorer Soul
emna__ayadi
2
1.1k
It's Worth the Effort
3n
188
29k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
400
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
380
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
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!