Karumi / Dexter

Android library that simplifies the process of requesting permissions at runtime.
http://karumi.com
Apache License 2.0
5.23k stars 671 forks source link

Manually clean up DexterInstance when DexterActivity is finishing #248

Closed EDLuke closed 4 years ago

EDLuke commented 4 years ago

:pushpin: References

:tophat: What is the goal?

Make state clean up synchronous.

:memo: How is it being implemented?

Manually clean up the state by calling onActivityDestroyed when there already is a DexterActivity that is finishing up. Then, when DexterActivity calls onDestroyed, no cleaning is needed.

:robot: How can it be tested?

Since testing this requires mocking activity life cycle events. Suggestions are welcome.

pedrovgs commented 4 years ago

Hi @EDLuke I'm going to take a look at this PR. Thanks for your contribution! If you are interested in the testing part, you can take a look at how you can simulate the activity lifecycle in your tests using this Robolectric API 😃

EDLuke commented 4 years ago

I spent some time playing with ActivityScenario and SingleActivityFactory and so far haven't landed on concrete way to test this without a major refactor.

The scenario I need to test is:

  1. Dexter.with()...check()
  2. Dexter launches DexterActivity
  3. DexterActivity.finish()
  4. Dexter.with()...check()
  5. DexterActivity.onDestroy()
  6. assert that the attributes set in Step 4 are wiped out (or kept after the fix)
pedrovgs commented 4 years ago

Ok @EDLuke don't worry about the tests. This scenario is not easy to test at all. I've been taking a look at your PR and is just perfect. Thank you so much for your contribution!! I'm going to merge this PR and release a new Dexter version with the fix.