Hello and thanks always.
I have been reading tutorials about Android programming and I have the following question. In one tutorial the instructor used a private variable to hold a button (and other things such as EditTexts Radio buttons, etc) but in the next lesson- and without giving a reason - he used a private static variable.
Something like this:
So I would like to ask which should I use? static or non static...?
Now I know the basic definition for static variables in classes in java. Class member variables vs Object member variables... you dont need to instantiate the class...
But in android?? Is MainActivity being instantiated?? I guess so because non static variables work fine.... but by who??
Any comment will be greatly appreciated
I have been reading tutorials about Android programming and I have the following question. In one tutorial the instructor used a private variable to hold a button (and other things such as EditTexts Radio buttons, etc) but in the next lesson- and without giving a reason - he used a private static variable.
Something like this:
Java:
public class MainActivity extends AppCompatActivity {
private Button first_button; // Non static or
private Static Button second_button; //Static?
//some other code
public void listenerForButtons(){
first_button=(Button)findViewById(R.id.button1);
second_button=(Button)findViewById(R.id.button2);
//some more other code...
}
//etc
So I would like to ask which should I use? static or non static...?
Now I know the basic definition for static variables in classes in java. Class member variables vs Object member variables... you dont need to instantiate the class...
But in android?? Is MainActivity being instantiated?? I guess so because non static variables work fine.... but by who??
Any comment will be greatly appreciated