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 Acivity I need to pass that data to the second class without the use of Intent. Any code samples would be appreciated.
Since I got it to work like I intended it to post what I have. In my case I already had a Constructor that was an ArrayList and for what I was doing I needed another one of the same type. So here goes:
ClassActivity
public class Polygon extends Overlay {
ArrayList<GeoPoint> geoPoints;
public Polygon(ArrayList<GeoPoint> points){
geoPoints = points;
}
public class Hex{
public Hex(ArrayList<String> str) {
// TODO Auto-generated constructor stub
Log.i("string",str.toString());
}
}
and My main Actvity has
Polygon main = new Polygon(null);
Polygon.Hex mMainClass = (main.new Hex(color));
Note that I had to create an instance of the main class before
Polygon.Hex mMainClass = (main.new Hex(color));
If your Class Name is
MainClassthen CreateConstructorfor that and pass value as a parameter, below is a example for that.MainClass.java
Use below code for Pass Value from MainActivity to MainClass, Here
iis integer variable andstris a String variable