In android, how can i transfer values from xyz.java to main_activity.java......providee that xyz.java is a simple java class and doesn't belong to any activity. I am working with an api , when i run it as simple .java file it is working fine bit not with activity file.?.
Asked
Active
Viewed 159 times
-2
-
Can you be more specific on what you mean saying " when i run it as simple .java file it is working fine bit not with activity file" – Ravi Mar 15 '19 at 15:22
-
There is a simple java file and the default activity_main.java file.I need to transfer data from simple java file to activity_main.java. – Divyanshu Gaur Mar 15 '19 at 15:29
2 Answers
0
You need to instantiate the xyz.java class in your main_activity.java like :
xyz xyzInstance = new xyz();
You can then access the public methods and attributes of xyz class using
int x = xyzInstance.value;
You can also make the values inside xyz class static and directly access the values like :
int x = xyz.value;

LalitaCode
- 410
- 4
- 10
0
first of all you need to create Xyz.java class object like this:
Main_Activity.java
Xyz x=new Xyz();
//use x object to get values from xyz class
int value=x.mydata;
Xyz.java
class Xyz
{
public int mydata=10;
}

Android Geek
- 8,956
- 2
- 21
- 35