« 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 | 48 Comments »

August 5th, 2025 at 19:33
… [Trackback]
[…] Read More Info here to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
August 7th, 2025 at 18:21
… [Trackback]
[…] Info to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
August 27th, 2025 at 12:54
… [Trackback]
[…] Read More Info here on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
September 19th, 2025 at 21:44
… [Trackback]
[…] Info on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
October 12th, 2025 at 19:25
… [Trackback]
[…] Read More on to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
October 16th, 2025 at 13:34
… [Trackback]
[…] Info on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
October 28th, 2025 at 23:13
… [Trackback]
[…] Find More here on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
November 19th, 2025 at 19:57
… [Trackback]
[…] Read More on to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
November 21st, 2025 at 22:29
… [Trackback]
[…] Read More Information here to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
December 4th, 2025 at 00:29
… [Trackback]
[…] Find More Information here to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
December 13th, 2025 at 22:48
… [Trackback]
[…] Read More here on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
January 29th, 2026 at 23:11
… [Trackback]
[…] Info to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
February 1st, 2026 at 21:52
… [Trackback]
[…] Read More Information here to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
February 4th, 2026 at 03:12
… [Trackback]
[…] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
March 9th, 2026 at 22:22
… [Trackback]
[…] Read More here on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
March 13th, 2026 at 21:56
… [Trackback]
[…] There you will find 51518 more Info on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
March 24th, 2026 at 01:51
… [Trackback]
[…] Find More on to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
April 3rd, 2026 at 01:48
… [Trackback]
[…] Read More to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
April 24th, 2026 at 14:35
… [Trackback]
[…] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 13th, 2026 at 03:50
… [Trackback]
[…] Information to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 14th, 2026 at 19:04
… [Trackback]
[…] Read More here on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 15th, 2026 at 20:14
… [Trackback]
[…] Here you will find 1264 additional Information to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 17th, 2026 at 04:08
… [Trackback]
[…] Read More here to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 17th, 2026 at 20:35
… [Trackback]
[…] Here you will find 72803 additional Information on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 18th, 2026 at 17:31
… [Trackback]
[…] There you will find 38469 more Information on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 18th, 2026 at 18:44
… [Trackback]
[…] Info on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 19th, 2026 at 07:00
… [Trackback]
[…] Find More Info here on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 22nd, 2026 at 16:32
… [Trackback]
[…] Find More here on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 26th, 2026 at 18:36
… [Trackback]
[…] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 27th, 2026 at 19:15
… [Trackback]
[…] Here you will find 53424 additional Info on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 28th, 2026 at 20:00
… [Trackback]
[…] Find More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 28th, 2026 at 20:22
… [Trackback]
[…] Find More Information here to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 28th, 2026 at 20:52
… [Trackback]
[…] Information to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 29th, 2026 at 09:56
… [Trackback]
[…] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 30th, 2026 at 18:18
… [Trackback]
[…] Read More on to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
May 30th, 2026 at 18:58
… [Trackback]
[…] Find More Information here to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
June 5th, 2026 at 18:20
… [Trackback]
[…] Read More on on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
June 5th, 2026 at 22:25
… [Trackback]
[…] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
June 6th, 2026 at 20:20
… [Trackback]
[…] Here you will find 31025 more Info on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
June 8th, 2026 at 05:31
… [Trackback]
[…] Read More Information here to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
June 8th, 2026 at 18:26
… [Trackback]
[…] Information on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
June 8th, 2026 at 19:21
… [Trackback]
[…] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
June 9th, 2026 at 19:31
… [Trackback]
[…] Find More here to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
June 9th, 2026 at 20:44
… [Trackback]
[…] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
June 10th, 2026 at 22:41
… [Trackback]
[…] Information on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
June 11th, 2026 at 14:17
… [Trackback]
[…] Find More on to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
June 15th, 2026 at 18:14
… [Trackback]
[…] Info to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]
June 16th, 2026 at 18:37
… [Trackback]
[…] There you will find 68659 additional Information to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]