Compdigitec Labs

« | Home | »

Techniques for testing Android fragments

By admin | March 4, 2013

How to test a fragment-based Android application:

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 »

48 Responses to “Techniques for testing Android fragments”

  1. ครูเกอร์ Says:
    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/ […]

  2. Read The Article Says:
    August 7th, 2025 at 18:21

    … [Trackback]

    […] Info to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  3. link Says:
    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/ […]

  4. บริการพ่นฉนวนพียูโฟม Says:
    September 19th, 2025 at 21:44

    … [Trackback]

    […] Info on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  5. รับผลิตของพรีเมี่ยม Says:
    October 12th, 2025 at 19:25

    … [Trackback]

    […] Read More on to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  6. รับทำเว็บไซต์ Says:
    October 16th, 2025 at 13:34

    … [Trackback]

    […] Info on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  7. ศูนย์ดูแลผู้สูงอายุ Says:
    October 28th, 2025 at 23:13

    … [Trackback]

    […] Find More here on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  8. Executive Search Says:
    November 19th, 2025 at 19:57

    … [Trackback]

    […] Read More on to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  9. พิสตาชิโอ เพสท์ Says:
    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/ […]

  10. EA Forex Says:
    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/ […]

  11. รับงานเอง Says:
    December 13th, 2025 at 22:48

    … [Trackback]

    […] Read More here on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  12. บทความ LSM99 Says:
    January 29th, 2026 at 23:11

    … [Trackback]

    […] Info to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  13. 123bet Says:
    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/ […]

  14. Ethical Elephant Sanctuary Says:
    February 4th, 2026 at 03:12

    … [Trackback]

    […] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  15. vps forex Says:
    March 9th, 2026 at 22:22

    … [Trackback]

    […] Read More here on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  16. switching Says:
    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/ […]

  17. suzuran168 Says:
    March 24th, 2026 at 01:51

    … [Trackback]

    […] Find More on to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  18. pin up авиатор Says:
    April 3rd, 2026 at 01:48

    … [Trackback]

    […] Read More to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  19. Thermage Says:
    April 24th, 2026 at 14:35

    … [Trackback]

    […] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  20. ร้านแอร์สมุทรปราการ Says:
    May 13th, 2026 at 03:50

    … [Trackback]

    […] Information to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  21. เมโสหน้าใส Says:
    May 14th, 2026 at 19:04

    … [Trackback]

    […] Read More here on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  22. เน็ตบ้าน ais Says:
    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/ […]

  23. engagement rings vancouver Says:
    May 17th, 2026 at 04:08

    … [Trackback]

    […] Read More here to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  24. sports urge Says:
    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/ […]

  25. staccato 2011 Says:
    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/ […]

  26. open the live scores page Says:
    May 18th, 2026 at 18:44

    … [Trackback]

    […] Info on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  27. morning prayer guide Says:
    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/ […]

  28. Peptide Gray Market In China Says:
    May 22nd, 2026 at 16:32

    … [Trackback]

    […] Find More here on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  29. เครื่องเป่าแอลกอฮอล์ Says:
    May 26th, 2026 at 18:36

    … [Trackback]

    […] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  30. เติมแอพพรีเมี่ยม Says:
    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/ […]

  31. แทงหวยออนไลน์เกาหลี Says:
    May 28th, 2026 at 20:00

    … [Trackback]

    […] Find More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  32. ufakorea Says:
    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/ […]

  33. เว็บพนันออนไลน์เกาหลี Says:
    May 28th, 2026 at 20:52

    … [Trackback]

    […] Information to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  34. sito ufficiale Says:
    May 29th, 2026 at 09:56

    … [Trackback]

    […] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  35. ledger wallet, ledger, ledger wallet download Says:
    May 30th, 2026 at 18:18

    … [Trackback]

    […] Read More on to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  36. sabaibet168 Says:
    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/ […]

  37. power wash driveway Says:
    June 5th, 2026 at 18:20

    … [Trackback]

    […] Read More on on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  38. Angthong National Marine Park Says:
    June 5th, 2026 at 22:25

    … [Trackback]

    […] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  39. essentials Says:
    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/ […]

  40. ปั้มคนดูไลฟ์ Says:
    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/ […]

  41. ledger live, ledger download, ledger wallet, ledger live download Says:
    June 8th, 2026 at 18:26

    … [Trackback]

    […] Information on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  42. trezor suite, trezor suite download Says:
    June 8th, 2026 at 19:21

    … [Trackback]

    […] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  43. tìm hiểu thêm Says:
    June 9th, 2026 at 19:31

    … [Trackback]

    […] Find More here to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  44. ต่อผม Says:
    June 9th, 2026 at 20:44

    … [Trackback]

    […] Read More on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  45. kupabet Says:
    June 10th, 2026 at 22:41

    … [Trackback]

    […] Information on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  46. ผลบอล Says:
    June 11th, 2026 at 14:17

    … [Trackback]

    […] Find More on to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  47. th盻拱 ti蘯ソt ト雪サ渡g Nai hテエm nay Says:
    June 15th, 2026 at 18:14

    … [Trackback]

    […] Info to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  48. โคมไฟ Says:
    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/ […]

Comments