Тёмный
No video :(

Process Death and ViewModels (My apps are BROKEN) 

CodingWithMitch
Подписаться 145 тыс.
Просмотров 12 тыс.
50% 1

Опубликовано:

 

6 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 78   
@Zhuinden
@Zhuinden 4 года назад
Hey, I'm just seeing this video, I'm glad I've helped create more reliable apps! At times, talking about process death can feel like fighting windmills (just the other day some guy on Twitter said "onSaveInstanceState for legacy applications" what? modern apps crash when put to background?!), so happy to see this tutorial video that shows just what can happen if you're not careful :)
@codingwithmitch
@codingwithmitch 4 года назад
I literally had no idea how to test for this before you opened an issue on my github repo. onSavedInstanceState seems like the only reliable way to do this. What is he talking about legacy? lol
@Zhuinden
@Zhuinden 4 года назад
@@codingwithmitch Absolutely no idea. I think he just doesn't know that process death is a thing.
@24035709
@24035709 3 года назад
@@Zhuinden @CodingWithMitch he could be right. You can use "SaveStateHandle" instead of "OnsaveInstance"
@Zhuinden
@Zhuinden 3 года назад
@@24035709 SavedStateHandle uses onSaveInstanceState internally, the guy was effectively saying that you just don't have to care about saved instance state at all (supposedly because ALL user input is ALWAYS immediately stored in the database? but I haven't really seen anyone doing that)
@jaloveast1k
@jaloveast1k 4 года назад
Note: lt applies to all members of a fragment (not just viewmodels), in case if someone misunderstood. Basically you should save all the data required to re-initialize it.
@codingwithmitch
@codingwithmitch 4 года назад
Yes sorry if that wasn't clear
@akashsrivastava60
@akashsrivastava60 4 года назад
// This is great, bringing the issue to light! I've faced this, and didn't know what was happening //
@24035709
@24035709 3 года назад
Hey Mitch. I know this is one year old video. You could also use "SaveStateHandle" to save the data during process death instead of onSaveInstanceState. Just removes your boilerplate code in activities and fragments and does the same work as onSaveInstanceState.
@jayshah5695
@jayshah5695 2 года назад
Gabor is great! Learning a fair bit of stuff on android from your channel and some of his videos
@nicoqueijo
@nicoqueijo 4 года назад
Hey Mitch you should check out an Android Studio plugin called "ADB Idea". You can trigger process death, clear app data, start app, restart app, and many more from just one command. Very useful!
@franciscoandrade729
@franciscoandrade729 4 года назад
Isn't the app loading from saved instance Everytime the app goes to the background and opens again ? .. that will prevent from loading from viewmodel right?
@codingwithmitch
@codingwithmitch 4 года назад
Yes it does load from the saved instance. But you need to save the data that you're displaying in the view. Then set it when the state is restored. And no that is not preventing loading from the viewmodel. The viewmodels data is lost. That's why we need to restore it
@HritikGupta722
@HritikGupta722 4 года назад
Thank you for this tutorial. You really bring new content to your channel that most of the people haven't heard of.
@farazahmed7
@farazahmed7 4 года назад
There's a jetpack component that helps to reduce the boilerplate code you wrote. Its called "SavedState"
@gofudgeyourselves9024
@gofudgeyourselves9024 4 года назад
Please do your reaction on Kotlin Conf and especially on Multiplatform and Kotlin Native
@codingwithmitch
@codingwithmitch 4 года назад
That Kotlin conf intro video is hype. So many cool things
@gofudgeyourselves9024
@gofudgeyourselves9024 4 года назад
@@codingwithmitch so is that yes?
@codingwithmitch
@codingwithmitch 4 года назад
@@gofudgeyourselves9024 not sure. But it's a good idea. That would mean I gotta watch all the content. There's a shitload
@MishaAkopov
@MishaAkopov 4 года назад
Actually, you don't need to save and get state in fragment and pass to ViewModel. You can do it in ViewModel directly, please check SavedStateHandle
@codingwithmitch
@codingwithmitch 4 года назад
Go ahead and try that while using dagger to provide your viewmodel
@techmarinar
@techmarinar 3 года назад
Thanx man this was very helpful
@kaizen960
@kaizen960 3 года назад
Very informative! thanks
@vineedcool
@vineedcool 4 года назад
can someone tell me where should we initialise adapter inside fragments, most codebase shows it in either onCreateView or onViewCreated, but i think it should be initialised on onCreate since adapter is not related to android view class its just a generator of view right? and also onCreate is called once so we save on performance too, and the above code leak can also be solved using the same right? please help!
@mb1-9999
@mb1-9999 4 года назад
Can you make a video about jackpack navigation on modular app how to navigate on different modules? Like your app let's say you have a module call :login and you want to navigate to :blog list but is in other package how would you do?
@ajaydeepak9739
@ajaydeepak9739 4 года назад
That would be very helpful
@codingwithmitch
@codingwithmitch 4 года назад
Watch the powerful Android apps course. I do that. Also maintain a separate backstack for entries on the bottom nav codingwithmitch.com/courses/powerful-android-apps-with-jetpack-architecture/
@josephralph7640
@josephralph7640 3 года назад
Please make the Architecture course in Java. I will buy it
@codingwithmitch
@codingwithmitch 3 года назад
no more java
@gezafiqrullah5321
@gezafiqrullah5321 3 года назад
@@codingwithmitch that's right.KOTLIN FOT LYFE🔥
@zulqarnain7179
@zulqarnain7179 4 года назад
I also faced the same problem when I change the permission when the application is running. Do change permissions kill the process?
@commentsonthetube14
@commentsonthetube14 3 года назад
Permission add doesn't but I believe permission remove does.
@flaviobarros8305
@flaviobarros8305 4 года назад
Hi mitch , can you please also discuss a bit about App Signing from Google Play and how it works? ...as far as i got to understand is that it uploads your app with a new SHA1 key to google play store and that clashes with your original package key in database and as a result no data is loaded if you are using firebase, any idea on how to fix this ? Thanks in advance
@codingwithmitch
@codingwithmitch 4 года назад
no idea
@flaviobarros8305
@flaviobarros8305 4 года назад
@@codingwithmitch Thanks Mitch i actually figured it out it's running smoothly now
@mattgraves3709
@mattgraves3709 3 года назад
Edit. The problem I have is with myself. I started Android development in 2009 using Eclipse and I knew all about process death lmao... I took a few year detour in enterprise Web and it was the best years:( I am caught up now finally but for a while resented you being more knowledgeable about Android. I actually don't think you are anymore so thats good ;) ... but more importantly it doesn't matter. Stupid ego bullshit:) Great video and way to be man, way to be!
@redBloodHound
@redBloodHound 4 года назад
Process death can be simulated with *Don't keep activities* option enabled in developer options.
@codingwithmitch
@codingwithmitch 4 года назад
Another way yes. I prefer doing this so I don't need to change any settings
@schwrz1
@schwrz1 4 года назад
This is wrong, that will destroy the activity NOT the app process. The closest approach is to set "background process limit" to "no background processes" but this is not guaranteed to happen in all devices.
@Zhuinden
@Zhuinden 4 года назад
`Don't keep activities` does NOT simulate process death. Static variables (and if I know correctly, even ViewModels) survive, so it's not equivalent behavior. Also, `don't keep activities` pretty much only happens if that option is enabled.
@codingwithmitch
@codingwithmitch 4 года назад
@@Zhuinden Whoops I forgot to correct myslf here
@codingwithmitch
@codingwithmitch 4 года назад
I'm wrong see replies below above from @Zhuinden
@Hulkdx
@Hulkdx 4 года назад
Why to use saveInstanceState from onCreate and not onViewCreated?
@codingwithmitch
@codingwithmitch 4 года назад
I mentioned this in the video. By the time OnViewCreated is called the views have already been restored so it's too late. The data needs to be in the viewmodel before the views are restored
@Zhuinden
@Zhuinden 4 года назад
Also, the `savedInstanceState` in `onViewCreated` can actually be out of date if you are returning to the Fragment via back navigation (it can run multiple times, but savedInstanceState will contain the last execution of `onSaveInstanceState`).
@theonlyarjun
@theonlyarjun 4 года назад
hey, mitch, while trying to kill the process via android studio, my app restarts, any idea how I can replicate it on my app?
@codingwithmitch
@codingwithmitch 4 года назад
That's the point. The process is killed therefore the app has to restart.
@theonlyarjun
@theonlyarjun 4 года назад
@@codingwithmitch hmm....thanks, I figured it out on you last video wherein your reviewed that Meam app.
@vineedcool
@vineedcool 4 года назад
​@@codingwithmitchi would like to point out even after process death fragment stack can be retained if you add frag as if (savedInstanceState == null) fragmentManager.beginTransaction().add(rootLayout, fragment).commit(MainFragment.newInstance())
@oscarperry641
@oscarperry641 4 года назад
ill be honest i have no idea what you are talking about but i still watch your videos and subbded liked many videos just to watch you talk so gorgeous beautiful beast
@RohitSingh-hi1gy
@RohitSingh-hi1gy 4 года назад
Hi, my application does not lose data but it opens my home fragment even if I am in profile fragment ??
@codingwithmitch
@codingwithmitch 4 года назад
So it opens as of being opened for the first time?
@RohitSingh-hi1gy
@RohitSingh-hi1gy 4 года назад
@@codingwithmitch yes, expect the selected bottom navigation icon is profile tab and the visible fragment is home fragment.
@codingwithmitch
@codingwithmitch 4 года назад
@@RohitSingh-hi1gy it's probably restarting completely or something
@RohitSingh-hi1gy
@RohitSingh-hi1gy 4 года назад
@@codingwithmitch i think so bt i have to fix this issue actually i was testing process death issue.
@RohitSingh-hi1gy
@RohitSingh-hi1gy 4 года назад
​@@codingwithmitch I think this is the way to save state via ViewModel : Persist ViewModel state across process recreation (beta) codelabs.developers.google.com/codelabs/android-lifecycles/#6
@BRUHItsABunny
@BRUHItsABunny 4 года назад
on OnePlus phones (their OxygenOS ROM) process death is god awful
@codingwithmitch
@codingwithmitch 4 года назад
I actually tested on a OnePlus one I literally couldn't get the process to die. Of course I mean by trying to overload it, not manually triggering it from android studio. And my OnePlus 5 is awesome to. What OnePlus have you tested with?
@BRUHItsABunny
@BRUHItsABunny 4 года назад
@@codingwithmitch I've got the 5 too More so referring to how OxygenOS kills apps wayyyyyyyyyy too fast through regular use truth be told i never tried to artificially induce a process death in this way though, all i know is how the only 2 messengers i have keep dying out of nowhere It happens on my 3 and 5, not noticed on 7t just yet because i didn't install anything on it yet
@codingwithmitch
@codingwithmitch 4 года назад
@@BRUHItsABunny Hmm interesting. My guess is that this isn't because of low memory conditions. Prob some other random thing. I can't think of any time my apps have done that and I've been using OnePlus for about 4 years. Check this out, this is what I did TRYING to get OnePlus one to kill a process. Lol I tried everything and it still wouldn't. github.com/mitchtabian/Open-API-Android-App/issues/4#issuecomment-561421167
@BRUHItsABunny
@BRUHItsABunny 4 года назад
@@codingwithmitch mhm, ive stopped using my One, it doesnt charge that well anymore imma see if i can get it to work on my 3
@dev_jeongdaeri
@dev_jeongdaeri 4 года назад
What happened?!
@user-px1zh4id7q
@user-px1zh4id7q 4 года назад
iduno
@codingwithmitch
@codingwithmitch 4 года назад
I died
@rashedulhasan5372
@rashedulhasan5372 4 года назад
I heard it too.. Eventually Mitch got hit by a pack of jets 😜
@codingwithmitch
@codingwithmitch 4 года назад
@@rashedulhasan5372 ☠️
@Firespirit233
@Firespirit233 4 года назад
I hate android because of this thing. I knew it from the very beginning when i've started developing. I'm so jealous for all ios devs, if the system runs out of memory it's just restarting the whole app and no problems whatsoever. and they don't even care about screen rotation. A lot of work we are doing as android devs has already been taking care of in ios. I'm thinking to switch and never come back to android again. It's 2020 now and i can't still store my data in ram. I should create some persistent secure storage solution. Room doesn't provide any security and encryption. The hacker can steal all the data from room just having root access to the user's device.
@begalisydykov6404
@begalisydykov6404 4 года назад
If you don't want to restore fragments from backstack after process death follow this answer stackoverflow.com/a/39722596/8942811
@jithind-feverx2818
@jithind-feverx2818 3 года назад
❤️👍
@GakisStylianos
@GakisStylianos 4 года назад
The thumbnail hahahaha
@codingwithmitch
@codingwithmitch 4 года назад
😉
Далее
UI Testing with Jetpack and AndroidX (course demo)
8:24
Bike Challenge
00:20
Просмотров 12 млн
How to test ANY APP for PROCESS DEATH
7:05
Просмотров 5 тыс.
6 Design Patterns Every Android Developer Must Know
14:16
Modularizing Android Apps
18:16
Просмотров 20 тыс.
Learn Android Process Death in 6min
6:27
Просмотров 14 тыс.
The iPhone 16 Will Tear Apple Fans Apart
7:38
Просмотров 65 тыс.
Android ViewBinding in 8 Minutes
8:59
Просмотров 76 тыс.