« Compiling mingw-w64 with GCC 4.8 | Home | Generating slope fields / direction fields with python and gnuplot »
Techniques for testing Android fragments
By admin | March 4, 2013
How to test a fragment-based Android application:
- Switching fragments directly from a sub-fragment (inside backstack) – This tests how well your fragment switching code deals with backstacks while switching fragments.
- Switching from another top level fragment – This tests your fragment switching code.
- Turning off the screen – This tests your onResume() and onResumeFragments() handlers
- Opening another activity from a fragment – Same as above
- Opening another activity from the action bar – Same as above
Preferably test in the “don’t keep activities” mode, as this will root out a ton of bugs related to the Android lifecycle – i.e. when Android decides to kill an old activity of yours.
Case Study:
User complaint: http://forum.videolan.org/viewtopic.php?f=35&t=108743
The story so far… old versions of the VLC for Android beta, up to 0.0.10, suffer from a bug, where trying to delete something in another fragment causes the other (non-visible) fragment to receive the onContextItemSelected() call. After setting user visibility hints for that bug, a series of fragment related bugs appeared, mostly involving IllegalStateException in android.support.v4.app.FragmentManager
because of duplicate fragments being added.
The problems were caused when Android decided to kill unused background activities. The interface code would try to recreate and re-add() fragments, even though Android had automatically recreated them via “android.support.fragments” in the onCreate() bundle. This would manifest after opening another activity, shutting the screen off, or having a system popup appear.
The solution was to keep better track of currently-added fragments, as member variables of the main activity may not necessarily be kept after the activity was hidden. To solve the problem, a check was implemented in onRestoreFragments() to ‘recall’ fragments that were already added. This fixed the problem permanently.
The moral of the story: watch and manage fragments very carefully in order to prevent problems.
If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!
Topics: Mobile | 9 Comments »
November 2nd, 2024 at 20:53
… [Trackback]
[…] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
November 9th, 2024 at 03:35
… [Trackback]
[…] Find More on to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
November 17th, 2024 at 21:50
… [Trackback]
[…] Info on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
November 22nd, 2024 at 06:44
… [Trackback]
[…] Information to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
December 1st, 2024 at 23:24
… [Trackback]
[…] Here you will find 64851 additional Info on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
December 3rd, 2024 at 01:01
… [Trackback]
[…] Read More Info here on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
December 9th, 2024 at 22:32
… [Trackback]
[…] Read More on to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
December 15th, 2024 at 21:46
… [Trackback]
[…] Read More Info here on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
December 19th, 2024 at 00:06
… [Trackback]
[…] Information to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]