How to Create a Class-Level Variable

1. Create an Android project, if you don't already have one.

2. In the MainActivity.java file,  add your new variable between the public class and the onCreate method. Below the String variable myString is declared class-level.

public class MainActivity extends Activity {

    String myString;  

    @Override
    public void onCreate(Bundle savedInstanceState) {
    ....

3. Compile and run!

Resources: