java - How to access user input from an activity to another class? -
i have activity called particleactivity
in 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
, batterylevel
declared user input in fields can accessed class, customusecase
.
public class customusecase extends test { public arraylist<double> costdata = mainactivity.costdata; //costs user enters 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 isn't way of writing code says on android studio
memory leak because android
components shouldn't declared static variables. way (from little knowledge of android
) can think off can access user input edittext
fields in particleactivity
can used in customusecase
class. can give me way can write out? thank you.
try using intent
class , putextra
method see docomentation here https://developer.android.com/reference/android/content/intent.html
example usage
intent = new intent(particleactivity.this,customusecase.class) i.putextra("myshow","one");
then on customusecase class
intent i=getintent(); string show=i.getstringextra("myshow");
Comments
Post a Comment