Issue
I know this question has been discussed several times like here and here.
But my problem is still not solved because most solutions provided are either not suggested or deprecated.
I have an AsyncTask
in which I update a TextView
text continuously. The execution of the task is started in a toggle button click. Initially I had the AsyncTask
as an inner class to the main activity. But I later changed it to an external class.
I am using onSaveInstanceState()
and onRestoreInstanceState()
methods to store and restore the textview value during an orientation change. What I am not able to achieve is after the orientation, how do I restore the button state and also resume the AsyncTask
?
Solution
According to this page : http://developer.android.com/guide/topics/manifest/activity-element.html#config, if your application targets API level 13 or higher, you should use android:configChanges="orientation|screenSize"
to catch the screen rotation into the onConfigurationChanged()
method.
By doing this, the onPause
and onResume
methods are not called, so your TextView will keep its value. And in my mind, it won't stop the running AsyncTask. If it does, try to recall it in the onConfigurationChanged
method.
Answered By - grattmandu03
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.