Ahmed Khairy
Ahmed Khairy

Reputation: 145

Android resetting all fields of a class

Hey guys I have a class called UserData consisting of static fields, which is as follows:

    public class UserData  {
private static JSONObject fbProfilePicture;
private static boolean loggedOut=false;
private static Integer commonFriendID;
private static Integer userID1;
private static Integer UserID2;
private static JSONObject stolenTrio=null;
}

Actually the class contains alot more fields but I decided to show you a small version of my class. In my app, I've a feature to delete account and create a new one, when I choose to do that, my app goes back to the sign up process, but there's a problem, I want to clear all fields of that class after deleting user. How can I do that?

Upvotes: 0

Views: 1099

Answers (2)

Stoica Mircea
Stoica Mircea

Reputation: 782

Create a method that reset your values. You might want later to do more things into that method. Ex inform a listener that your object has been cleared.

Upvotes: 0

fweigl
fweigl

Reputation: 22028

If you think you need a static / singleton kind of instance of UserData, I suggest doing it like this:

public class UserDataSingleton {
   public static UserData userdata; 
}

and make your UserData a simple Pojo with non-static fields. This way you can reset your data with

UserDataSingleton.userData = new UserData()

Upvotes: 1

Related Questions