In the first class I created a HashMap: HashMap<String, String> test = new HashMap<>(); And then send a variable called name to a database. Code:
HashMap<String, String> test = new HashMap<>();
test.put("name", name);
In the second class in Java, I want to send a variable called surname, in this class, but it must be in the same HashMap, because I want to send it to the same database. Please how to do this in Android Studio? Because it is not possible to apply multiple inheritance, since the classes in Android Studio already extend the AppCompatActivity.
If you write only:
test.put("surname", surname");
Android won't understand the object called "test", because it does not extends the HashMap in the first class.
If you declare:
HashMap<String String> test = new HashMap<>();
test.put("surname", surname);
it will send to another database, but I want it to send in the same database in the first class.
Can anyone help please?
you can create a constants class
class Constants {
public static final HashMap<String, String> test = new HashMap<String,String>();
}
In other classes you can use the test HashMap
class Worker1 {
public hashMapFunc() {
Constants.test.put('this', 'this' );
}
}
class Worker2 {
public hashMapFunc() {
Constants.test.put('that', 'that' );
}
}
etc