1

there are some functions that I use in most activities in the project, I want to have them defined somewhere and just call for them when needed.

I tried to store them in a Class its possible but not efficient, is there a file that i can store all these function definitions in?

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
MalSept
  • 11
  • 1
  • *If* you really want to do that you need to create one central class and either make it a singleton or make the helper methods in it static. – luk2302 Mar 18 '18 at 14:19
  • You can declare them as static methods in a general class. – Dorian Gray Mar 18 '18 at 14:20
  • just create a Utility class and put all methods in it . You can also use `SingletonPattern` for it (In case) . Take reference from classes of package `java.util`. – ADM Mar 18 '18 at 14:22
  • you could make a superclass that you could extend with every activity – fab Mar 18 '18 at 14:24
  • 1
    One option is to create your own library and then import it into your project. This will only work if each of your methods are standalone however. – DrRoach Mar 18 '18 at 14:35
  • It would be helpful if you elaborated on why you state it is "not efficient" - possibly due to many dependencies (i.e. lots of parameters?) which may mean more decomposition. –  Mar 18 '18 at 15:04
  • @Andy "not efficient" is for the need to create an object of the class in order to call a function, but making it static (as mentioned in other comments) would raise the "efficiency". – MalSept Mar 19 '18 at 10:45

0 Answers0