开发者

Does switching activities in Android start a fresh JVM

开发者 https://www.devze.com 2022-12-24 10:51 出处:网络
Does switching activities in Android start a fresh JVM?It seems like each activity is meant to run as its own \"main\" method.If I have a singleton (via Guice, not an actual singleton in this case) sh

Does switching activities in Android start a fresh JVM? It seems like each activity is meant to run as its own "main" method. If I have a singleton (via Guice, not an actual singleton in this case) should I expect to be re-creating it 开发者_Go百科every time I switch activities?


What I know about Android and programming in general is entirely hacked-together and not formally taught so perhaps other people will need to correct me, but that said, I don't think Android starts new virtual machines all the time. I've read that it uses the Dalvik VM rather than the standard JVM. I couldn't tell you what exactly that entails though. However switching activities is meant to be a lightweight operation as an application can easily have several of them. If it had to recreate the Dalvik VM each time, that wouldn't seem to make sense, particularly as Activities can easily pass information between each other, call each other's methods, etc. You can even have one activity start entirely separate applications/tasks while still allowing some communication between them, so again I don't think it would have to start another Dalvik VM in that situation either.

Judging from your other question about why we'd want to have multiple activities I'm assuming you're new to Android; have you had a good read through its documentation, such as the fundamentals, particularly the activity lifecycle? Sometimes the information is a bit sparse, and often they assume the reader understands Java already, but that shouldn't be an issue for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号