Single activity: Why, when, and how (Android Dev Summit '18)

Sdílet
Vložit
  • čas přidán 7. 11. 2018
  • With the Navigation Architecture Component, developers have the tools to move towards a single activity structure for their app, but they don't know:
    - why they should move to that model
    - when it is appropriate
    - how exactly to take advantage of that structure and migrate to it
    Navigation Architecture Component → bit.ly/2zGSmme
    Testing Fragments → bit.ly/2qzf37w
    Presented by: Ian Lake
    Android Dev Summit '18 all sessions playlist → bit.ly/ADS18-Sessions
    Subscribe to the Android Channel! → bit.ly/AndroidDevs1
    #AndroidDevSummit event: Android Dev Summit 2018; re_ty: Publish; product: Android - Jetpack; fullname: Ian Lake;
  • Věda a technologie

Komentáře • 101

  • @IanLake
    @IanLake Před 5 lety +202

    I was really happy to share a lot of the best practices around activities, Fragments, Navigation, and most importantly *making your code testable*. Thanks for watching!

    • @Soulcybering
      @Soulcybering Před 5 lety +3

      One of the best talk for sure. Handling activities navigations it's always a pain. Cant wait to see the progress to the final Navigation component. Thank you 😊

    • @999Souls
      @999Souls Před 5 lety +2

      The best talk for sure. I'm using the navigation component and it is very good. Thank you !

    • @LiranBarsisa
      @LiranBarsisa Před 5 lety

      Is there maybe a tiny sample for trying it?
      Also, suppose we already have a huge app, with many activities, do you suggest to do the switch to this type?
      It doesn't seem like it has a lot of advantages...

    • @utkarshshukla5252
      @utkarshshukla5252 Před 5 lety

      thanks a lot for providing examples also in documentLaunchMode section

    • @ramprasad357
      @ramprasad357 Před 5 lety +1

      But i dont understand why Android frameworks are very complex even after 10 years of Android. Lot of libraries,I have go through the testing document, I cant understand which library I need to add, which one I need to leave. Lot of confusions. Is it any consolidated document to start unit testing in my fresh project. Also I have a new library called Truth for assertions. Why not Google combine these under single roof? It looks like options for lot of developers but again Google going into fragmentation issues without any control of their developers.

  • @Stilgarnaibfremen
    @Stilgarnaibfremen Před 5 lety +30

    One of the best videos so far of the Android Dev Summit '18. And probably the best speaker so far too. Clear, concise, to the point and relaxed. Very easy to follow and really well explained. Thanks Ian!!

    • @IanLake
      @IanLake Před 5 lety +5

      Thanks for the kind words!

  • @brainplot
    @brainplot Před 5 lety +6

    Great talk! Can we find some sample app to get an idea of how all the pieces fit together? Sometimes I got lost with the code examples so having a little app to experiment with would greatly help me.

  • @Rumikimoku
    @Rumikimoku Před 5 lety +25

    Ian's videos are always my favourite 'cause he's always passinote and enthusiastic. Keep up the good work, you're amazing. And thanks for the video.

    • @IanLake
      @IanLake Před 5 lety +3

      Thanks! Sharing that passion with you all is really my favorite part of giving talks.

  • @PeterKeefe
    @PeterKeefe Před 5 lety +1

    Ian's the best. His Udacity courses were great too :-). Now I'm off to bug my manager to make the app single activity haha.

    • @IanLake
      @IanLake Před 5 lety

      Like I said at the end, don't contort yourself if it doesn't make sense. Moving each Activity one at a time to Navigation until each is just an empty shell of an Activity makes it a lot easier to later combine the graphs and collapse multiple Activities into one without it being a 'big bang' kind of approach. Updating the Migrating to Navigation guide to call out the steps to make that transition is definitely something we're working on - feel free to star the feature request to track progress: issuetracker.google.com/issues/119646049

  • @famketheron7475
    @famketheron7475 Před 5 lety +11

    Have been using single activity pattern for a while (4 years or so). Banner ads can perform uninterrupted and register more impressions when a single activity pattern is employed.

    • @raymondakkasel5588
      @raymondakkasel5588 Před 3 lety

      hello sir, i'm still a beginner on android development and i want to ask you something, in Single Activity Architecture, how you can hide the Bottom Navigation Bar on Child Fragments?

  • @RajSingh-lt9eo
    @RajSingh-lt9eo Před 2 lety

    superb way of explaining ...

  • @codinginflow
    @codinginflow Před 5 lety +18

    MAGICAL~

    • @blockbusterlatefees7713
      @blockbusterlatefees7713 Před 5 lety

      I LOVE YOUR VIDEOS! THEY HAVE HELPED SO MUCH!
      Even your videos teach Multi-Activity Development. I don't understand Single Activity Development. Using Fragments seems too much like a delicate balancing act. It also seems like double the code without the flexibility and customization.

    • @codinginflow
      @codinginflow Před 4 lety +2

      @@blockbusterlatefees7713 Thank you very much! I saw your comment just now. I'm planning to make a tutorial on Navigation Component with single activity architecture

    • @edwinfcapidos
      @edwinfcapidos Před 3 lety

      @@codinginflow is it already uploaded?

  • @clublulu399
    @clublulu399 Před 4 lety

    Great vid!

  • @harshpatel-bt5wr
    @harshpatel-bt5wr Před 3 lety +1

    how can we handle multiple backstack with Navigation component? can we handle multiple navigation graph with this ?

  • @radosawjuszczyk638
    @radosawjuszczyk638 Před 5 lety +2

    What about destroying invisible activities and recreating them when user navigates back to it in order to save memory and resources? Did we stopped to care about that and expect phone manufactures to put more RAM in phones than we used to have in our computers?

  • @alicewang837
    @alicewang837 Před 4 lety

    Great talk!

  • @fidanbacaj
    @fidanbacaj Před 5 lety +7

    Its good practice to use two navigation(in two deferents activities ) in same app ?
    example : one navigation for (register ,login) and second navigation for (navigation drawer) ?

    • @Pulkit__7
      @Pulkit__7 Před 5 lety

      haha, I guess, it makes sense to do this way, so I am also gonna do this only, 2 activities, in total. Did you find any other approach, please let us know :P

    • @MartinLichtblau
      @MartinLichtblau Před 5 lety

      That's how I always do it, since the both are totally detached.

  • @rob2theworld
    @rob2theworld Před 5 lety +2

    Very nice, but what's happens when you have a app where some screens have a navbar or drawer and some screens do not? Can you really do the same with one activity

    • @Existentialkev
      @Existentialkev Před 5 lety +2

      Wouldn't it be as simple as hiding those views depending on what fragment is visible?

  • @raghuthetraveler
    @raghuthetraveler Před 5 lety +2

    How does this work with when you have app that supports phones and tablet. For example a master detail view on tablet?. In tablet we don't add or replace the fragment as master and detail fragment are side by side. Different navigation graph for phones and tablets??

    • @okay89284dj
      @okay89284dj Před 5 lety

      You can have two layouts in your Single Activity on your res/layout-large variant and from the Activity react upon your current screen size which is also easy to determine with a res/values large variant

    • @IanLake
      @IanLake Před 5 lety +2

      I talked about this in some detail in this reddit AMA: www.reddit.com/r/androiddev/comments/8xspo7/were_on_the_engineering_team_for_android_p_ask_us/e2ojrwn/ - basically, due to free-form multi-window being available on Chrome OS devices, you should focus on *every* screen of your app being responsive rather than making huge changes like switching to master/detail. We're working on making that more officially part of our documentation - you can star the feature request for updates on that: issuetracker.google.com/issues/79668915

    • @raghuthetraveler
      @raghuthetraveler Před 5 lety

      @@IanLake thanks. cleared most of my doubts.

  • @alikali8952
    @alikali8952 Před 4 lety

    Thanks

  • @DeLL116
    @DeLL116 Před 5 lety +35

    I'm pretty sure I'm fed up with Android. Been with it since 2009, but I think it's getting to a point where a lot of what I've spent years mastering are getting reworked, and I don't want to go through the struggles of mastering all this new stuff again. Not to mention all the new "gotcha's" that are going to come along with all these new APIs (remember when fragments came along?). Plus, while I'm busy as hell at work, on what do I spend the 30-45 minutes in the day to learn, Kotlin or Flutter?
    You've been good and bad to me, Google. Maybe it's time we spend some time apart.

    • @IanLake
      @IanLake Před 5 lety +15

      Hopefully, the things that are being reworked are being reworked because they were difficult to work with and required a lot of workarounds and arcane knowledge that is just no longer needed. As an example, compare the navigate call at 12:08 with the FragmentTransaction code you would have had to write (not to mention things like animations, etc. that can be baked into that call automatically).
      Sometimes times the best code to write is no code at all and I feel like the higher level libraries available today mean you get to spend a lot more time working on the actual unique business logic of your app than the boilerplate that dominated apps in 2009. Work smarter rather than harder eh?
      That's not to mention the super open development process of all of the AndroidX libraries (all in AOSP, public bugs on the issue tracker such as issuetracker.google.com/issues?q=componentid:409828) that means even if you do encounter a problem, you have a good chance of getting an engineer to look at your issue and actually just fix it for everyone.

    • @SasLuca
      @SasLuca Před 5 lety +9

      My feelings exactly, the Android ecosystem and API is a nightmare for developers. Google has a clear patern of bad decisions when it comes to Android.

    • @ristekostadinov2820
      @ristekostadinov2820 Před 5 lety

      Flutter looks great and have a lot of hype, Alibaba have rebuild their app with Flutter and its still such a new framework. I think that it has a lot of potential and it performs well for animations. You are also targeting both android and ios.

    • @JustinTipton
      @JustinTipton Před 5 lety +3

      Did the old APIs quit working? If you've mastered the old APIs, seems like you are good to go. You don't even need to watch this video if you have mastered the old APIs. ;-)

    • @antonimysliborski3649
      @antonimysliborski3649 Před 5 lety +10

      I'm afraid that unless you specialise in some legacy technology like Cobol, no matter what you do in IT you'll need to constantly learn some new stuff and approaches

  • @IlyaPaskhover
    @IlyaPaskhover Před 5 lety +5

    ...
    36:09 Dynamic Feature Modules
    37:45 Thank you! (summary)

  • @ranganrangan5633
    @ranganrangan5633 Před 2 lety

    How can we participate in google submit?

  • @maverikgames6882
    @maverikgames6882 Před 3 lety +2

    Not knowing that you don't know of what there is to know is easy once you know it!

  • @darwinspace
    @darwinspace Před 3 lety

    Im stuck with login flow and navigation 🙁

  • @haobinli4449
    @haobinli4449 Před 5 lety +6

    For a real world app that has many screens to follow the Single Activity approach, I can think of two possible scenarios.
    First, a single ViewModel is used and shared by all destinations. This single ViewModel is going to be bloated and not scalable. For this reason, I think the first approach is not suitable for real world development.
    Second, multiple ViewModels are used. (Not necessary one ViewModel per destination but would be close.) Given the lifecycle of a ViewModel is tied to the lifecycle of the (single) Activity, how is a "cold" (instantiated by no longer needed) ViewModel going to be released?

    • @jackball8219
      @jackball8219 Před 5 lety

      Word

    • @mandisaw
      @mandisaw Před 5 lety +1

      IIRC Memory management was one of the reasons they used to consider single-Activity as an anti-pattern for all but the simplest apps (or games & native apps, which were ostensibly doing their own memory-management anyway).

    • @areebjamaliam
      @areebjamaliam Před 5 lety +4

      " Given the lifecycle of a ViewModel is tied to the lifecycle of the (single) Activity" Where did you read that? ViewModels are life cycle aware of any LifeCycle owner. Fragments are LifeCycle owners as well

    • @Pulkit__7
      @Pulkit__7 Před 5 lety +1

      @@areebjamaliam nice to know :)

    • @Zhuinden
      @Zhuinden Před 5 lety

      1.) you can create your own ViewModelStoreOwner and 2.) they have made NavGraphs become ViewModelStoreOwners.

  • @PatrickJonas
    @PatrickJonas Před 5 lety +1

    ENJOY THANKSGIVING

  • @FaisalMohammedtly
    @FaisalMohammedtly Před 5 lety +7

    thanks for effort.
    As a feedback:
    As usual, it turned another Google presentation focused nothing. Atleast, as a developer I was expected to hear in depth about navigation.

    • @IanLake
      @IanLake Před 5 lety +8

      Yep, for a lot of seasoned developers, none of this should be a surprise, although we did talk about FragmentScenario and FragmentFactory which were literally just released and help considerably towards not just making a Single Activity structure work, but also make it testable.
      If you want in depth talks on Navigation, I'd suggest the I/O 2018 talk and the Droidcon NYC 2018 talk: czcams.com/video/ST2W1Y_Ztvk/video.html

  • @OffTheChuckyBaby
    @OffTheChuckyBaby Před 2 lety +2

    25:37: "Use cases for multiple activities"

    • @Kemakemak
      @Kemakemak Před rokem

      Thanks, this was what I came here for!

  • @ranganrangan5633
    @ranganrangan5633 Před 2 lety +1

    How to restrict fragment recreation in this architecture?

    • @user-lf5nt1cm7h
      @user-lf5nt1cm7h Před rokem

      I also want to know how to achieve it.Are we going in the wrong direction?

    • @user-lf5nt1cm7h
      @user-lf5nt1cm7h Před rokem

      After all this time, have you found a solution? Maybe we can talk about it.Time has passed so long, have you found the corresponding solution? Maybe we can talk about it.

  • @AdiTrioka
    @AdiTrioka Před 5 lety +13

    need a codelab for this

    • @IanLake
      @IanLake Před 5 lety +13

      Codelabs are super helpful, yep! We have both a Navigation codelab at codelabs.developers.google.com/codelabs/android-navigation/ and a codelab about responsive Android apps which I think fits well with a single activity structure: codelabs.developers.google.com/codelabs/chromeos-resizing/

    • @AdiTrioka
      @AdiTrioka Před 5 lety

      @@IanLake yass! thank you, Ian :3

    • @danishamjad4816
      @danishamjad4816 Před 4 lety

      @@IanLake is this a recommended architecture now?

    • @IanLake
      @IanLake Před 4 lety

      @@danishamjad4816 - that's why I did the talk, yep.

    • @danishamjad4816
      @danishamjad4816 Před 4 lety

      @@IanLake Thanks for quick reply 🙂

  • @green6564
    @green6564 Před 5 lety

    Good

  • @martinseal1987
    @martinseal1987 Před 5 lety

    Picture in picture mode is so broken

    • @IanLake
      @IanLake Před 5 lety

      Yep, if you're using multiple activities, there's definitely some gotchas as described in medium.com/google-developers/navigation-patterns-with-pip-2c5b6a446ba0 - a lot of these are significantly minimized if you are using a single activity since that avoids any noticeable effects of the task change that occurs when entering picture in picture mode.

  • @GrumpyOldMan9
    @GrumpyOldMan9 Před 2 lety

    Is there a Java version of this video??

  • @SofienRahmouni
    @SofienRahmouni Před 4 lety +3

    Good practice in 2016 , then become Bad practice in 2018 ... all things with google is strange ..

  • @blockbusterlatefees7713
    @blockbusterlatefees7713 Před 5 lety +1

    This is WAY more confusing than Multiple Activity Development. Still interested in learning more though.

    • @Zhuinden
      @Zhuinden Před 5 lety

      It's possible to use a single-activity for the app, without all this complication, tbh.

    • @nickadams2361
      @nickadams2361 Před 3 lety

      @@Zhuinden That's what I was thinking. Alot of whats coming out of android team seems to be targeted at making devs more lazy instead of giving them real new tools. It's not that freaking hard to do transactions

    • @Zhuinden
      @Zhuinden Před 3 lety

      @@nickadams2361 i've been using and updating simple-stack and open-sourcing some then-internal components for simple-stack since writing this comment, you can always check what that's like over defining NavGraphs and Actions and generating code

  • @christinaarries831
    @christinaarries831 Před 2 lety

    Yeah I’m lost

  • @Skyliow-tr4mh
    @Skyliow-tr4mh Před 6 měsíci

    0:21

  • @brianjumandiema6406
    @brianjumandiema6406 Před 4 lety +7

    its been always kotlin these days on your IO presentations. Some of us are still java developers.

    • @azeddinehamdaoui8631
      @azeddinehamdaoui8631 Před 4 lety

      because there is no point using java in IO presentations nor documentation. Kotlin dominate android ecosystem for fair reasons.

    • @ruif3r
      @ruif3r Před 3 lety +1

      Time to switch

  • @llothar68
    @llothar68 Před 2 lety

    Not a good talk at all if you looking for practical tips or for the theory/architecture.

  • @AhmedAli-jx9ie
    @AhmedAli-jx9ie Před 5 lety +8

    android development is such a pain in the A@#

    • @KyleJMitchell
      @KyleJMitchell Před 5 lety +1

      That's a sure sign that you're doing it wrong.

    • @blockbusterlatefees7713
      @blockbusterlatefees7713 Před 5 lety +3

      Stick with Multi-Activity Development. Like he keeps saying, do what works best for you.

    • @arpanbag6730
      @arpanbag6730 Před 4 lety +2

      The only issue I have with android development is fragmentation..