I have an activity called ParticleActivity
in my Android Studio
project.
public class ParticleActivity extends AppCompatActivity {
public final static String EXTRA_MESSAGE = "pso.algo.MESSAGE";
private ProgressDialog pd;
private double[] results = {-1.0, -1.0, -1.0};
EditText particles = (EditText) findViewById(R.id.particles);
EditText iterations = (EditText) findViewById(R.id.iterations);
static EditText solution;
public static double userSolution = Double.parseDouble(solution.getText().toString());
static EditText battery;
public static double batteryLevel = Double.parseDouble(battery.getText().toString());
The userSolution
and batteryLevel
are declared so that the user input in those fields can be accessed by another class, customUseCase
.
public class CustomUseCase extends Test {
public ArrayList<Double> costData = MainActivity.costDATA; //costs that the user enters for each resource
public ArrayList<Double> costWlan = MainActivity.costWLAN;
public ArrayList<Double> costUtilities = MainActivity.costUTILITY;
public double batteryCost = ParticleActivity.batteryLevel; //battery cost user enters
public double userSolution = ParticleActivity.userSolution; //user's predicted solution
private int maxIter;
private int noParticles;
I know this isn't a good way of writing code as it says on Android Studio
that I will get a memory leak because the Android
components shouldn't be declared as static variables. But this is the only way (from my little knowledge of Android
) that I can think off where I can access the user input from the EditText
fields in ParticleActivity
so that it can be used in my customUseCase
class. Can someone give me a good way I can write this out? Thank you.