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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
240
プロダクト開発を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
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
190
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
260
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
600
Vite+ Unified Toolchain for the Web
naokihaba
0
300
RTSPクライアントを自作してみた話
simotin13
0
600
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
12k
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.1k
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
780
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
550
The NotImplementedError Problem in Ruby
koic
1
780
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
3
1.3k
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
120
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
210
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
780
Paper Plane (Part 1)
katiecoart
PRO
0
8.9k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
250
A designer walks into a library…
pauljervisheath
211
24k
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!