Although it seems easy but I stuck my head down for a while.
So I have my class Common.java as:
package com.spil.util;
public class Common extends Fragment implements SubscriptionListener
{
String WEBSERVICE = "http://webservice.carrierservice.com/";
}
And the class DownloadDataActivity.java as:
package com.spil.main;
public class DownloadDataActivity extends TimerTask {
String WEBSERVICE = "http://webservice.carrierservice.com/";
}
I don't want the string WEBSERVICE
to be repeated so I thought to access it from Common.java.
So I changed Common.java
to have string WEBSERVICE
as:
public static String WEBSERVICE = "http://webservice.carrierservice.com/";
And then in DownloadDataActivity.java
, I am accessing it as:
public static String WEBSERVICE = Common.WEBSERVICE ;
This works fine but my question is:
Is it a good practice to change string variable to public static string variable just to access it in another class and how it will affect the scope as I assume that making this url as public will allow it to be accessible from anywhere ?
But I didn't find any alternative than to just define the URL twice in each class.