Hi there! It seems like there is little to none in...
# android
d
Hi there! It seems like there is little to none information about the fact that android recreates the activity when an exception is thrown inside a ViewModel class (instead of just crashing the app). Upon doing so, some of my app resources are left in an inconsistent state. I would rather let it crash instead. Can anyone help me with some information in this regard?
c
I don’t think that is Android ViewModel behavior, but you might see that if you have Crashlytics, Fabric, or other crash reporting tools installed
d
I created a simple app to reproduce the behavior: throwing the exception on button click from Activity -> crashed the app, but doing so from the ViewModel, recreates the activity first, and the second time crashes the app
w
How would that even work? It’s not that all the calls in view model are magically wrapped in try..catch 🤔
z
this only happens if you use
FLAG_ACTIVITY_NEW_TASK
iirc
d
@zhuinden Indeed, there seems to be something related to starting a new activity when reproducing this issue, yet I do not still understand why.. as I am starting the new Activity using the simple
Copy code
startActivity(Intent(this, MainActivity::class.java))
I do not set a
FLAG_ACTIVITY_NEW_TASK
anywhere (niether Manifest, nor directly on Intent starting this new Activity)
Also, crashing inside the Activity, always displays the Crash popup and closes the app, but doing so inside the ViewModel, <sometimes> it just “eats” the crash, and closes current Activity, displaying the previous screen as if nothing bad happened.
I kept on testing, and I discovered that the crash does not have to be inside the ViewModel.. it can be reproduced in an Activity also, but first time only, crashing a second time will display the dialog. Is this a native behavior?! (my test project has
compileSdk
&
targetSdk
set to
28
)
w
, <sometimes> it just “eats” the crash, and closes current Activity, displaying the previous screen as if nothing bad happened.
not all crashes are shown as dialogs
In developer options there’s
always show crash dialog
option. Iirc at some point Android stopped showing each crash, since the user can sometimes even miss that the app has crashed (it just seems like recreating the activity)
d
Guys, this is off-topic
👮‍♂️ 1
Please see the channel topic.