Using static keyword
static int a=10;
static void display()
{
System.out.println(a+5);
}
You can call static method directly with your activity class.Remember static method can only hold static members.
Classname.method();
Classname.variable;
Another way to pass data is using Intent & Bundle:-
Make intent with your destination class and add key with it's value.Put this
code in that activity from where you want to send data.
Intent intent = new Intent(context, DestinationActivity.class);
intent.putExtra(Key, Value);
startActivity(intent);
Now to receive the data
Intent intent = getIntent();
String str = intent.getStringExtra(Key);
To get diff. types of data use getIntExtra(),getFloatExtra(),getStringExtra()
To access other class variables/methods Make Object of your activity class and use it with "." seperator in order to use class variables or methods.
Classname objname = new Classname();
objname.variable;
objname.method();
Ex:-Suppose class name is DemoActivity having variables int a,b and add().
DemoActivity objdemo = new DemoActivity();
objdemo.a;
objdemo.add();