AsyncTask runs in the background while the action is complete. So getActivity () returns null. You should modify your code as follows and pass the context in the constructor of your AsyncTask.
private class Logo extends AsyncTask<Void, Void, Void> { private Context context; public Logo(Context context) { this.context = context; } @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected Void doInBackground(Void... params) { try {
Then you can call your AsyncTask in Activity as follows:
Logo logo = new Logo(this); logo.execute();
Hope this solved your problem !; -)
Sincerely.
Robin source share