I have created Three Classes, namely Mainactivity which is passing context to server class extending to Asynctask
. There one class named setting, which call server class for updating data in server.
Code on Mainactivity for passing Context:
Server.setActivityContext(getApplicationContext());
Code for Sever Class:
public class Server extends AsyncTask<Void, Void, Void> {
static Context mycontext;
public static void setActivityContext(Context receivingcontext) {
mycontext = receivingcontext;
}
Dialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = ProgressDialog.show(mycontext, "Updating ..", "Please wait......");
}
@Override
protected Void doInBackground(Void... params) {
//Background task
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
dialog.dismiss();
}
}
I am getting an error on progressdialog
when calling this server class. Though context is passed, any fixes which you can suggest.
Error:
FATAL EXCEPTION: main
Process: jss.smartapp, PID: 22915 android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
Don't use static methods. Use a proper constructor.
Call it with