i saw a lot of posts saying that you should put your async task inside a Fragment(i dont remember other ways), so you can rotate screen and keep it...
but its not working for me
Activity shows the Fragment;
MyGetJsonFragment frag= ....
frag.setRetainInstance(true);
fm = getSupportFragmentManager();
ft = fm.beginTransaction();
ft.replace(R.id.fragment_main, frag);
ft.commit();
than, inside this Fragment i have a RecyclerView, and when the user click in any item on list, it call the Adapter and inside the adapter onBindViewHolder i implemented the onClick to call the AsyncTask
holder.button_get.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new AsyncGet(activity, AdapterList.this).execute();
}
});
if i use the configChanges ( android:configChanges="orientation|keyboardHidden|screenSize
)
at manifest it works normal, but i heard and read that this is not a good workaround!
after removed the configChanges, if i rotate the screen, the progress dialog dismiss and than on the post execute i get the error at progressdialog.dissmiss or anyother thing that dependes the activity
i understood the activity life cycle that when i rotate the original that started the async is destroyed and new one is created...
but how can i handle it and still show the progressdialog?
i need the Context/Activity at the async to start the progress and i have some db methods inside the postExecute that use Activity/Context
and why setRetainInstance(true)
is not holding the Instance?