java - How can I move functions to a separate file in android studio? -
how can move functions separate file in android studio?
for example, if following code in mainactivity.java:
public class mainactivity extends appcompatactivity { int var1; int var2; int var3 ... protected void onstart() { ... var1 = 102; var2 = 105; var3 = add( var1, var2); ... } public void add ( int var1, int var2 ) { return var1 + var2; } }
how can have :
mainactivity.java
public class mainactivity extends appcompatactivity { int var1; int var2; int var3 ... protected void onstart() { ... var1 = 102; var2 = 105; var3 = add( var1, var2); ... } }
functions.java
public void add ( int var1, int var2 ) { return var1 + var2; }
in "utils.java"
public static string getanydata(){ return "anydata"; }
called mainactivity (e.g.)
utils.getanydata();
but keep in mind utility functions / methods should work that. no oop!
intellij / androidstudio has neat shortcut task.. see here.
Comments
Post a Comment