For asynctask to deal with activity rotation, I find this solution: 
https://github.com/commonsguy/cw-android/blob/master/Rotation/RotationAsync/src/com/commonsware/android/rotation/async/RotationAsync.java
 .
However, getlastnonconfigurationinstance() is deprecated in API level 13 (
http://developer.android.com/reference/android/app/Activity.html#getLastNonConfigurationInstance()
 ) 
and fragment is recommended.
I think that fragment is more graceful than asynctask like the code 
mentioned above in terms of attaching to and detaching from an 
activity because fragment lifecycles manage them. Besides, fragment can be 
retained on rotation.
 
Therefore, I take a look at *
http://developer.android.com/guide/components/fragments.html*<http://developer.android.com/guide/components/fragments.html>
 and 
read "For an example activity that uses a fragment as a background worker, 
without a UI, see the FragmentRetainInstance.java sample." .
After reading the source code of FragmentRetainInstance.java, I have 
question on this line 
"getFragmentManager().beginTransaction().add(android.R.id.content, new 
UiFragment()).commit();".
It adds the UiFragment()) to the layout and starts the worker thread in 
RetainedFragment consequently.
 
I would like to modify the worker thread to perform network operation 
according to user interaction. For example, when a user fire a 
View.OnClickListener event, I add the fragment in order to perform network 
operation.
Is it okay to add the fragment multiple times if users fire more than one 
event? Will it lead to some side effect (to view hierarchy)?
 
The other question, why
    synchronized (mThread) {
        mReady = false;
        mThread.notify();
    }
appears in both onDestroy() and onDetach()?
Aren't they duplicate because the thread is gone when onDestroy() returns? 
Why try to stop the thead again in onDetach()?
 

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to