[SOLVED] Where to put "general" functions in Android?

Issue

I want to write a general function for my project that will be used across many different files and I don’t want to have it in a particular class.

Where am I supposed to put it?
Inside a new package as a class?

Is this the only option?

Solution

Create a new package as util and create all common methods in there, for example:

Create package as com.xyz.util.

Create a class as Util in above package.

Then write your all common methods in this Util class.

You can write static methods in this class and access them as Util.method_name();.

Answered By – Bishan

Answer Checked By – Marie Seifert (BugsFixing Admin)

Leave a Reply

Your email address will not be published.