What is the best way to pass variable data from an Activty
to a non-Activty
class? The data is created within the onCreate
of the first
If your Class Name is MainClass
then Create Constructor
for that and pass value as a parameter, below is a example for that.
MainClass.java
public class MainClass {
public MainClass(int i, String str) {
// TODO Auto-generated constructor stub
}
}
Use below code for Pass Value from MainActivity to MainClass, Here i
is integer variable and str
is a String variable
MainClass mMainClass = new MainClass(i, str);
Create a class object in that activity class.
MyClass mc = new MyClass();
mc.yourVariable = "Your Value";