-2

My question is regarding in creating a method to be used in my android app. This method is a blackbox that accepts string as a parameter then converts the string object into something.

I want to call this method everytime a certain button is clicked (from a fragment and activity) and I'm wondering if static is the better approach for this since i dont need to instantiate.

I read the answer in Difference between Static methods and Instance methods and says that static is better but i found a blog that one should avoid static as possible.

So what's better approach to implement for my blackbox method?

Community
  • 1
  • 1
cattarantadoughan
  • 509
  • 1
  • 6
  • 15
  • 1
    That is merely a matter of taste in this case. Personally, I'd probably create a singleton for that. – Fildor Nov 24 '15 at 20:24

1 Answers1

0

If you place your method in activity class which contains button with onClickListener calls this method, there is no need to make it static, because the instance of activity created anyway.

If you use a separate class with utils methods, then it may be a good idea to use a static method.

This article is simple explanation of rules to make a method static in Java

Intentio
  • 72
  • 2
  • 9