My MainActivity spans some (ie. 4) webviews CustomWebView. This class has a static method BROADCAST that broadcast some message to all instantiated children.
-
so inside the activity context, i can do
CustomWebView.BROADCAST (BECOME_RED)and all CustomWebViews would become red.
-
All is fine but now my main activity spans a
subactivity(ie. select a picture activity). The original activity becomes stopped (itsonstop()called blah blah blah)
So… What would happen now, in the context of this new subactivity, with its parent activity stopped, should I do:
CustomWebView.BROADCAST (BECOME_RED)
-
I’ve seen it “works” but dont really understand the implications of the owner activity being stopped and I messing with its views accessing them “illegally” from a static context.
-
What about if the static method access the View, but only non-view related stuff such as an ArrayList?
-
What about if the static method does NOT access a child instance, but uses exclusively static variables? Does it make a different?
-
What about the lifetime of the View object (static stuff mainly) when the activity is stopped?
Static members of class live as long as class is loaded (also, as long as JVM is running in case of android). But views are created with a context ( also Activity ) and have pretty intimate private relation – AFAIK, they should not be used with multiple activities.
Activity stop does not mean that it is destroyed – it can be reactivated at later time. View instances survive this.