I have been searching the internet, but could not get the correct answer that I need. I am new to Android, so please provide a detailed answer.
I have a Fragment which gets some data from the user, ex: name, occupation etc. Every single time I get the data, I would like to store it using GSON to sharedPreferences. Based on the searches, I will need to construct a regular Java user class and pass the object (Android - save Object to SharedPreferences and get it anywhere in the app).
So the question that I have is, can Fragments access other regular java class functions?
class UserFragment extends Fragment { // get the data from editText User newUser = new User("Tom"); newUser.setOccupation("Programmer"); //etc }
Can a Fragment instantiate a class and set variables?
- If yes to 1 and 2, where do we add the user class java file, same file as the fragment implementation of another folder and then include it?
I just provided a user as an example, but generically I would like to know the answer to 1 and 2.
Thanks