Android global variable

前端 未结 14 1084
眼角桃花
眼角桃花 2020-11-21 23:32

How can I create global variable keep remain values around the life cycle of the application regardless which activity running.

14条回答
  •  北恋
    北恋 (楼主)
    2020-11-21 23:51

    import android.app.Application;
    
    public class Globals extends Application
    {
        private static Globals instance = null;
        private static int RecentCompaignID;
        private static int EmailClick;
        private static String LoginPassword;
        static String loginMemberID;
        private static String CompaignName = "";
        private static int listget=0;
        //MailingDetails
        private static String FromEmailadd="";
        private static String FromName="";
        private static String ReplyEmailAdd="";
        private static String CompaignSubject="";
        private static int TempId=0;
        private static int ListIds=0;
    
        private static String HTMLContent="";
        @Override
        public void onCreate() 
        {
            super.onCreate();
            instance = this;
        }
    
        public static Globals getInstance()
        {
            return instance;
        }
    
        public void setRecentCompaignID(int objRecentCompaignID)
        {
            RecentCompaignID = objRecentCompaignID;
        }
    
        public int getRecentCompaignID() 
        {
            return RecentCompaignID;
        }
    
        public void setLoginMemberID(String objloginMemberID) 
        {
            loginMemberID = objloginMemberID;
        }
    
        public String getLoginMemberID() 
        {
            return loginMemberID;
        }
    
        public void setLoginMemberPassword(String objLoginPassword)
        {
            LoginPassword = objLoginPassword;
        }
    
        public String getLoginMemberPassword()
        {
            return LoginPassword;
        }
    
        public void setEmailclick(int id)
        {
            EmailClick = id;
        }
    
        public int getEmailClick() 
        {
            return EmailClick;
        }
        public void setCompaignName(String objCompaignName)
        {
            CompaignName=objCompaignName;
        }
        public String getCompaignName()
        {
            return CompaignName;
        }
        public void setlistgetvalue(int objlistget)
        {
            listget=objlistget;
        }
        public int getlistvalue()
        {
            return listget;
        }
        public void setCompaignSubject(String objCompaignSubject)
        {
             CompaignSubject=objCompaignSubject;
        }
        public String getCompaignSubject()
        {
            return CompaignSubject;
        }
        public void setHTMLContent(String objHTMLContent)
        {
            HTMLContent=objHTMLContent;
        }
        public String getHTMLContent()
        {
            return HTMLContent;
        }
        public void setListIds(int objListIds)
        {
            ListIds=objListIds;
        }
        public int getListIds()
        {
            return ListIds;
        }
        public void setReplyEmailAdd(String objReplyEmailAdd)
        {
            ReplyEmailAdd=objReplyEmailAdd;
        }
        public String getReplyEmailAdd()
        {
            return ReplyEmailAdd;
        }
        public void setFromName(String objFromName)
        {
            FromName=objFromName;
        }
        public String getFromName()
        {
            return FromName;
        }
        public void setFromEmailadd(String objFromEmailadd)
        {
            FromEmailadd=objFromEmailadd;
        }
        public String getFromEmailadd()
        {
            return FromEmailadd;
        }
    }
    

提交回复
热议问题