It seems that many actions can be performed in either the onCreate()
method for an activity or in the variable initializer section at the
beginning of the class definition. For example, I could write:
public class Main extends Activity {
private Handler handler = new Handler();
. . .
or I could write:
public class Main extends Activity {
private Handler handler;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
handler = new Handler();
. . .
What are the considerations that would make me want to do the
initialization in one place rather than the other? Both forms of
initialization happen exactly once whenever the class is instantiated,
right? And the variable initializers at the top happen before the
code in onCreate() is run. But are there any other considerations as
to where I should initialize values for variables?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en