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
290
プロダクト開発をAI 1stに変革する〜SaaS is dead時代で生き残るために〜 / AI 1st Product Development
kobakei
0
3k
今日から始める依存性の注入 / 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.7k
開発者が知っておきたい通知の歴史
kobakei
9
7.9k
Other Decks in Programming
See All in Programming
「人を評価する AI」の設計と実装
ryoyanara
0
220
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
160
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
130
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
530
Dockerfile CMD for Node.js
grazie1999
0
110
React本体のコードリーディング
high_g_engineer
1
150
FastAPI の並行処理モデルを完全に理解する
hoto17296
1
590
Building a Meta Ray-Ban display app
akkeylab
0
170
Claude Code全社展開のためにやったことn選~プラグイン302個・コミッター271人を支えるために~
kenchan
5
1.6k
運用ダッシュボードの設計を誰も教えてくれないのだけどみなさんどうしてるんですか? - チームに監視するという文化を根付かせるための第一歩を踏みたい -
satoshi256kbyte
1
140
「つくるAI」だけではバグは見つからない ~テストに必要な「見つけるAI」を分離させる戦略~
mfunaki
0
120
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
500
Featured
See All Featured
Visualization
eitanlees
152
17k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Designing for Timeless Needs
cassininazir
1
450
Google's AI Overviews - The New Search
badams
0
1.1k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
800
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
GraphQLとの向き合い方2022年版
quramy
50
15k
Agile that works and the tools we love
rasmusluckow
331
22k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
410
YesSQL, Process and Tooling at Scale
rocio
174
15k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
A better future with KSS
kneath
240
18k
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!