-4

I have About 15-20 Activity which uses the same function again and again I want to know is there any way to write that function once and call it again and again.

As writing the same piece of code again and again is going to be tough task and it will be very difficult if I have to change anything.

The function doesn't require any parameters, it's a simple function, which has no relation with current Activity.

Dimitar
  • 4,402
  • 4
  • 31
  • 47
bhaskarkh
  • 179
  • 2
  • 11

2 Answers2

0

Is there Any way to use one Function in All activity of android

Yes you can use one function in all activity

Try this

public class Utils {
    public static void myMethod(){

    }
}

than use like this way to call your method

Utils.myMethod();
Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31
-1

Yes , you can create one utility class and paste that function into that , make it static , then you can access that function using that class name

public class Utility{

      public static methodName() {
        // your logic
    }

}

then call it using Utility.methodName()

vm345
  • 813
  • 12
  • 28