From my MainActivty I'm trying to call a method of non-activity class with the following line:
Context context;
context = getApplicationContext();
mClient.start(context);
In non activity-class:
public void start(Context context) {
final ProgressDialog startDialog;
startDialog = new ProgressDialog(context);
startDialog.setMessage("Loading...");
startDialog.setCancelable(false);
startDialog.show();
mHandler.post(new Runnable () {
@Override
public void run() {
Log.d(TAG,"Connecting to the server...");
try {
connect();
} catch (Exception e) {
}
startDialog.dismiss();
}
The app crashes with the following message:
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
Where's the mistake?