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 :)
@codingwithmitch5 жыл бұрын
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
@Zhuinden5 жыл бұрын
@@codingwithmitch Absolutely no idea. I think he just doesn't know that process death is a thing.
@240357094 жыл бұрын
@@Zhuinden @CodingWithMitch he could be right. You can use "SaveStateHandle" instead of "OnsaveInstance"
@Zhuinden4 жыл бұрын
@@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)
@jaloveast1k5 жыл бұрын
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.
@codingwithmitch5 жыл бұрын
Yes sorry if that wasn't clear
@akashsrivastava605 жыл бұрын
// This is great, bringing the issue to light! I've faced this, and didn't know what was happening //
@jayshah56952 жыл бұрын
Gabor is great! Learning a fair bit of stuff on android from your channel and some of his videos
@HritikGupta7224 жыл бұрын
Thank you for this tutorial. You really bring new content to your channel that most of the people haven't heard of.
@240357094 жыл бұрын
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.
@nicoqueijo4 жыл бұрын
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!
@farazahmed74 жыл бұрын
There's a jetpack component that helps to reduce the boilerplate code you wrote. Its called "SavedState"
@franciscoandrade7295 жыл бұрын
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?
@codingwithmitch5 жыл бұрын
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
@techmarinar3 жыл бұрын
Thanx man this was very helpful
@MishaAkopov4 жыл бұрын
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
@codingwithmitch4 жыл бұрын
Go ahead and try that while using dagger to provide your viewmodel
@kaizen9603 жыл бұрын
Very informative! thanks
@vineedcool4 жыл бұрын
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!
@josephralph76404 жыл бұрын
Please make the Architecture course in Java. I will buy it
@codingwithmitch4 жыл бұрын
no more java
@gezafiqrullah53214 жыл бұрын
@@codingwithmitch that's right.KOTLIN FOT LYFE🔥
@flaviobarros83055 жыл бұрын
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
@codingwithmitch5 жыл бұрын
no idea
@flaviobarros83055 жыл бұрын
@@codingwithmitch Thanks Mitch i actually figured it out it's running smoothly now
@mb1-99995 жыл бұрын
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?
@ajaydeepak97395 жыл бұрын
That would be very helpful
@codingwithmitch5 жыл бұрын
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/
@zulqarnain71795 жыл бұрын
I also faced the same problem when I change the permission when the application is running. Do change permissions kill the process?
@commentsonthetube143 жыл бұрын
Permission add doesn't but I believe permission remove does.
@oscarperry6414 жыл бұрын
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
@theonlyarjun5 жыл бұрын
hey, mitch, while trying to kill the process via android studio, my app restarts, any idea how I can replicate it on my app?
@codingwithmitch5 жыл бұрын
That's the point. The process is killed therefore the app has to restart.
@theonlyarjun5 жыл бұрын
@@codingwithmitch hmm....thanks, I figured it out on you last video wherein your reviewed that Meam app.
@vineedcool4 жыл бұрын
@@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())
@redBloodHound5 жыл бұрын
Process death can be simulated with *Don't keep activities* option enabled in developer options.
@codingwithmitch5 жыл бұрын
Another way yes. I prefer doing this so I don't need to change any settings
@dsantamaria905 жыл бұрын
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.
@Zhuinden5 жыл бұрын
`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.
@codingwithmitch5 жыл бұрын
@@Zhuinden Whoops I forgot to correct myslf here
@codingwithmitch5 жыл бұрын
I'm wrong see replies below above from @Zhuinden
@Hulkdx5 жыл бұрын
Why to use saveInstanceState from onCreate and not onViewCreated?
@codingwithmitch5 жыл бұрын
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
@Zhuinden5 жыл бұрын
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`).
@RohitSingh-hi1gy5 жыл бұрын
Hi, my application does not lose data but it opens my home fragment even if I am in profile fragment ??
@codingwithmitch5 жыл бұрын
So it opens as of being opened for the first time?
@RohitSingh-hi1gy5 жыл бұрын
@@codingwithmitch yes, expect the selected bottom navigation icon is profile tab and the visible fragment is home fragment.
@codingwithmitch5 жыл бұрын
@@RohitSingh-hi1gy it's probably restarting completely or something
@RohitSingh-hi1gy5 жыл бұрын
@@codingwithmitch i think so bt i have to fix this issue actually i was testing process death issue.
@RohitSingh-hi1gy5 жыл бұрын
@@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
@matt-g-recovers3 жыл бұрын
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!
@Firespirit2334 жыл бұрын
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.
@dev_jeongdaeri5 жыл бұрын
What happened?!
@ДмитрийМоргун-й9х5 жыл бұрын
iduno
@codingwithmitch5 жыл бұрын
I died
@rashedulhasan53725 жыл бұрын
I heard it too.. Eventually Mitch got hit by a pack of jets 😜
@codingwithmitch5 жыл бұрын
@@rashedulhasan5372 ☠️
@BRUHItsABunny5 жыл бұрын
on OnePlus phones (their OxygenOS ROM) process death is god awful
@codingwithmitch5 жыл бұрын
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?
@BRUHItsABunny5 жыл бұрын
@@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
@codingwithmitch5 жыл бұрын
@@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
@BRUHItsABunny5 жыл бұрын
@@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
@jithind-feverx28184 жыл бұрын
❤️👍
@begalisydykov64045 жыл бұрын
If you don't want to restore fragments from backstack after process death follow this answer stackoverflow.com/a/39722596/8942811