Actually, a FragmentActivity
will automatically restore your fragments in onCreate()
.
Weird thing is, you call AsyncTask
first, prior to calling through to super.onCreate()
and retrieving username and password from the Intent
.
Even having set that aside, that approach will make your activity spawn a new login task every time it's rotated.
Better way is to check savedInstanceState
for null
:
if (savedInstanceState == null) {
// first launch
new AsyncLogin().execute(username, password);
}
...
That way it's only going to run when Activity
is created for the first time.
Second, you need to completely unbind login info from your activity. Make the AsyncTask
return whatever login result you get to the Application
and store it there. And your activity and fragments to retrieve that info from the Application
- that way you get full control over you login procedure: you check whether there's an active session, if there isn't you check whether the AsyncTask
is already running, if it isn't - you need to launch it. If it is - you need to wait for it to finish (show progress bar or something).