I have an Application with a List of Objects on the main screen.
When clicking on one of them, I'm transferring the user to the next Fragment.
Then I have more 3 Fragments which are setting(manipulating) the object fields.
My question is, is it right instead of implementing the Serializable interface and pass the Object using Bunde I'll do kind of Singleton.
Something like this (I know that for Singleton I must do the empty constructor private).
public class Father {
private static Father instance;
private String name;
private int age;
Father() {
}
public static Father getInstance(Father father) {
if (instance == null) {
instance = new Father();
if(father != null) {
instance = father;
}
}
return instance;
}
Father regularFather = new Father();
regularFather.setAge(35);
regularFather.setName("Danny");
Father regularFather2 = new Father();
regularFather2.setAge(44);
regularFather2.setName("Mike");
Father regularFather3 = new Father();
regularFather3.setAge(15);
regularFather3.setName("Tom");
Father.getInstance(regularFather2).setName("Mike32");
System.out.println("regularFather name is: " + regularFather.getName()
+ " \n regularFather2 name is: " + regularFather2.getName()
+ " \n regularFather3 name is: " + regularFather3.getName()
+ " \n Instance name is: " + Father.getInstance(null).getName()
);
I test it, it works great, but my question is, is it right to do so and what if it can cause problems in the futere?