Passing Values From One Class To Another Android
Solution 1:
Since this is run time data, it is not suggested to use sharedpreference. Create a class with name RunTimeData.java. Declare all required variables here as static. Whenever you need to save data, save it to these variables. After using the data in other class make sure you will relase the variables by setting them to null.
Example.
publicclassRunTimeData{
publicstaticString name=null;
}
While assigning data do use as follows.
RuntimeData.name="yyyyy";
While using the data use as follows.
TextView tv=new TextView(); tv.setText(RunTimeData.name);
RunTimeData.name=null;
Release the variable when you are sure that you are not going to using the value once again somewhere.
Solution 2:
Create a SharedPrefencesHelper class,make it have all the global variables you want to use in your various classes,then you can use these variables anywhere in your application with simple getter methods.Look up SharedPreferences,it's very easy to use.
Post a Comment for "Passing Values From One Class To Another Android"