Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AsyncTask inside a Static method - Good Coding Practice?

I currently have a helper class to perform rudimentary AsyncTasks such as the following. I call the function from an activity as and when needed. The code seems to work fine and I haven't encountered any problems. But, I was wondering if this is a good coding practice or if there were any ramifications that I am unaware of. Any feedback would be gladly accepted and appreciated.

public class OtherUtils {

    public static void updatePromptsOption(final boolean showPrompt, final Context context) {
        new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
                Editor preferenceEditor = PreferenceManager.getDefaultSharedPreferences(context).edit();
                preferenceEditor.putBoolean(Constants.SHOW_PROMPT, showPrompt).commit();
                return null;
            }

        }.execute();    
     }
}
like image 915
Abhijit Avatar asked Feb 07 '12 22:02

Abhijit


1 Answers

I don't see anything wrong with doing things that way. Being a static function, you're not hiding implicit this references that could bite you later. Seems like a reasonable convenience function to me.

like image 193
Brian Dupuis Avatar answered Nov 15 '22 01:11

Brian Dupuis