Where should I save configuration data for Android backend

Sorry if this is a stupid question, but I have little experience developing applications. I am developing my own application that makes an ajax call for my backend (public API). My question is: Where should I save the configuration for ajax call? At the moment, I created my own static class called ConfigData, and in my application I call this class as

ConfigData.apiUrl

And in my ConfigData class I have

public static String apiUrl= "www.mysite.com/public/api";

But is there a better method?

+4
source share
3 answers

One possible way is to use buildConfigFieldin the build.gradle file

productFlavors {
    development {
        ....
        buildConfigField "String", "API_URL", "\"www.mysite.com/public/api\""
    }
}

Then you can access it through BuildConfig.API_URLin code

URL- , , ..

https://developer.android.com/studio/build/gradle-tips.html#share-custom-fields-and-resource-values-with-your-app-code

+4

string.xml URL- backend, URL- .

<string name="base_url">www.mysite.com/public/api/</string>
<string name="login">login.php</string>
<string name="get_data">getData.php</string>

java ,

String url=getResources().getString(R.string.base_url)+getResources().getString(R.string.login);
0

Source: https://habr.com/ru/post/1682641/


All Articles