嗨我有一個名爲的UserData由靜態字段的類,主要內容如下:的Android重置類的所有領域
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;
}
實際上類包含很多更多的領域,但我決定給你看小我班的版本。 在我的應用中,我有一個功能可以刪除帳戶並創建一個新帳戶,當我選擇這樣做時,我的應用可以回到註冊過程,但存在問題,我想清除該類的所有字段刪除用戶後。 我該怎麼做?
爲什麼所有這些「靜態」? –
正如@JoeC所暗示的,您應該使用非靜態屬性並在每次登錄時創建一個UserData實例。這樣,你可以簡單地創建一個新的UserData實例,並且你將擁有空的屬性。 –
@Joe C,因爲我不創建UserData的對象,在我的應用程序中,我使用它如下UserData.get/set(),因爲我不需要在我的應用程序中超過一個對象 –