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 | 20 Comments »

20 Responses to “Techniques for testing Android fragments”

  1. buy cz guns USA online Says:
    February 23rd, 2022 at 09:28

    … [Trackback]

    […] There you can find 76865 additional Information to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  2. UFABET เว็บตรง Says:
    April 9th, 2022 at 19:22

    … [Trackback]

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

  3. buy bergara guns Says:
    May 5th, 2022 at 11:12

    … [Trackback]

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

  4. เช่าเครื่องเสียง Says:
    May 30th, 2022 at 05:35

    … [Trackback]

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

  5. buy visa gift card with Cardano ada crypto anonymous 11 Says:
    May 31st, 2022 at 18:03

    … [Trackback]

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

  6. nova88 Says:
    June 25th, 2022 at 05:02

    … [Trackback]

    […] There you can find 32340 additional Info on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  7. grand daddy purple price Says:
    July 27th, 2022 at 11:41

    … [Trackback]

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

  8. sbo Says:
    August 15th, 2022 at 20:15

    … [Trackback]

    […] Here you will find 91414 more Info to that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  9. Buy dmt online Melbourne Says:
    August 31st, 2022 at 10:23

    … [Trackback]

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

  10. Rogue Company cheats Says:
    September 18th, 2022 at 09:26

    … [Trackback]

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

  11. sbo Says:
    October 21st, 2022 at 05:36

    … [Trackback]

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

  12. check Says:
    October 27th, 2022 at 11:47

    … [Trackback]

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

  13. best vapes for dmt Says:
    November 6th, 2022 at 13:32

    … [Trackback]

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

  14. sbobet Says:
    November 9th, 2022 at 06:10

    … [Trackback]

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

  15. cliquez pour plus Says:
    December 24th, 2022 at 13:00

    … [Trackback]

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

  16. 홀덤사이트 Says:
    February 1st, 2023 at 05:11

    … [Trackback]

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

  17. bienes raices loreto Says:
    February 18th, 2023 at 03:54

    … [Trackback]

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

  18. like it Says:
    February 25th, 2023 at 03:10

    … [Trackback]

    […] There you can find 32964 more Information on that Topic: compdigitec.com/labs/2013/03/04/techniques-for-testing-android-fragments/ […]

  19. polkadot mushroom chocolate bars revie Says:
    March 5th, 2023 at 16:23

    … [Trackback]

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

  20. Best Psychedelic Store Brisbane Says:
    March 15th, 2023 at 16:15

    … [Trackback]

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

Comments