Use Case:
The user will launch an application that will download captcha. The user will fill in captcha and try to download some information.
Problem:
If the user rotates the device while the Activity loading, it is destroyed. At the end of execution, AsyncTask tries to update the destroyed Activity , and the result - "not connected to the window manager.
Invalid solution:
I can mask the problem with android:configChanges="orientation|keyboardHidden|screenSize" , but with this the layout will not be updated to the landscape.
What am I asking:
Is it possible to change the orientation and change the "link" of the Context passed to AsyncTask ?
This answer suggests checking if the dialog is not null, but that is not what I am looking for.
Here he suggests using WeakReference ( here is a good snippet on how to use it), but I did not understand that this is what I am looking for.
To be more explicit, this is what I do in onPostExecute:
@Override protected void onPostExecute(Auto result) { progress.dismiss(); new DownloaderCaptcha(context).execute(""); ((EditText)context.findViewById(R.id.editTextCaptcha)).setText(""); context.findViewById(R.id.progrBar).setVisibility(View.VISIBLE); context.findViewById(R.id.captcha).setVisibility(View.INVISIBLE); if(result != null) { Storage.storeHistory(context, result.getTarga().getValue()); Intent i = new Intent(context, MenuActivity.class); i.putExtra("result", result); context.startActivity(i); } else { ErrorDialog.show(context, error); } }
Enrichman
source share