-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tasks not cleaned up after ActivityScenario.launch
#2152
Comments
I think this is working as intended. ActivityScenario.close essentially just calls Activity.finish. I'm not super familiar with recent tasks but I believe it will show anything recently launched. |
Hey, thanks for the response. Please let me clarify before you close this. The issue here is that blank white screen apps are being left open on my phone after tests complete "normally". This has to be unexpected behavior. Also, the docs for /**
* Call this when your activity is done and should be closed. The
* ActivityResult is propagated back to whoever launched you via
* onActivityResult().
*/
public void finish() {
finish(DONT_FINISH_TASK_WITH_ACTIVITY);
} Alternatively, there is /**
* Call this when your activity is done and should be closed and the task should be completely
* removed as a part of finishing the root activity of the task.
*/
public void finishAndRemoveTask() {
finish(FINISH_TASK_WITH_ROOT_ACTIVITY);
}
|
Thanks for the pointer. We probably could consider calling finishAndRemoveTask on the EmptyActivity if test is running on API >= 21, but more investigation would be needed on any potential side effects. I'd be nervous about changing existing behavior and modifying ActivityScenario.close to call finishAndRemoveTask instead of finish. One could easily argue that it is more expected for a recently used Activity to show up in Recent tasks |
Thank you for sharing your thoughts. I can see the valid arguments for ending an ActivityScenario with As for I wonder if selecting the activity dispose strategy could be a part of the ActivityScenario API, to support both methods? |
In general our philosophy with ActivityScenario is to try to focus on the most common use cases. There is a concern that too much niche functionality over complicates the API surface and makes it harder to use and maintain. If calling finishAndRemoveTask is important for your use case could you write your own custom logic on teardown to dispose of the activity? |
I can try. Please feel free to close this in the meantime. |
Description
I am trying for the first time to use
ActivityScenario.launch
in instrumented tests for a physical device. No matter what I do, I cannot get the tasks to be cleaned up.Steps to Reproduce
main
test
Expected Results
When the test is done, there are no running apps.
Actual Results
When the test is done, my phone shows 2 running apps.
If I run
adb shell dumpsys activity recents
, I see this at the bottom of the outputTo summarize, the
EmptyActivity
andMainActivity
were not properly cleaned up. On my phone, they actually show as two different apps in the recent app list. Both are blank white screens, but one of them says "matt.launch.MainActivity". The other one has no text.AndroidX Test and Android OS Versions
androidx.test: 1.5.0
android OS: 13
Link to a public git repo demonstrating the problem:
I did not make one because I am hoping there is a quick solution or that it will be easy to reproduce with the code I copied and pasted above. If there is not quick solution and it is not simple to reproduce, I will be happy to make a repo. Please just let me know.
The text was updated successfully, but these errors were encountered: