Which is best way to define constants in android, either static class, interface or xml resource?

后端 未结 6 1238
独厮守ぢ
独厮守ぢ 2020-12-07 14:28

I\'m developing an android application which uses web service to get data from server, for that I\'m having three different set of URLs to point development system, test ser

6条回答
  •  感情败类
    2020-12-07 15:06

    For the people who want to see how we can use a Class to define our constants and call any where we need.

    Constant.java

        package org.nrum.nrum;
    
    /**
     * Created by rajdhami on 5/23/2017.
     */
    public class Constant {
        public static final String SERVER = "http://192.168.0.100/bs.dev/nrum";
    //    public static final String SERVER = "http://192.168.100.2/bs.dev/nrum";
        public static final String API_END = SERVER + "/dataProvider";
        public static final String NEWS_API = API_END + "/newsApi";
        public static final String BANNER_API = API_END + "/bannerApi/lists";
        public static final String NOTICE_API = API_END + "/noticeApi/lists";
        public static final String UPLOAD_PATH = SERVER + "/uploads";
        public static final String UPLOAD_PATH_BANNER = UPLOAD_PATH + "/company_1/banner";
        public static final String UPLOAD_PATH_NEWS = UPLOAD_PATH + "/company_1/news";
        public static final int BANNER_TRANSITION_DURATION = 5000;
        public static final int NOTICE_BUTTON_BLINK_DURATION = 5000;
        public static final int BANNER_FETCH_LIMIT = 3;
    }
    

    Now we can use above constants in following way.

    Constant.NOTICE_BUTTON_BLINK_DURATION
    

提交回复
热议问题