can anyone guide me to the right direction, as the situation is have two classes calssA with Activity while classB is simple java class
1.classA has a editbox where the user inputs some value. 2.classB has a method that computes the user input.
need to get the user input value from classA to classB.
a).cannot get it through passing intent as the other class does not have activity. b).have tried getter setter method by creating a class thus,calling setter where the user inputs the detail. and calling the getter in another class.
Still the value is null, so what apparently is missing here.Any guidance to a example or brief explanation would be great.Thanks
You can use your own customized class to store the data and use it any where you need.
DataClass
In Activity
you can use this values in Java file like this
User a Class to hold your value
in Activity Class
you can use this when you dont want to persist your data. you can also refer to Ram kiran answer which is a better way.
OR
Also you can use SharedPrefernces if you want to persist your data and store it for later use.
To store values in shared preferences:
To retrieve values from shared preferences:
according to my knowledge here you have to use singleton class.
to set data
to get data
You can save the edittext value in SharedPreferences, thus making it available in all activity. By doing this you can fetch the value in other activity without any hassle.
eg:
Further fetching the value in other activity like this,
In your activity class create
and in your java class where you want