• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Starting activity in a loop

skill_

Lurker
Apr 20, 2011
2
0
The problem is following:
I need to run an activity again and again analysing results, until results match some conditions.
So I use
Code:
while(...)
{
...
StartActivityForResult(...); //Activity is not launched here
...
}
So I wonder how can I run an activity in a loop, and where and how should I analyse results.
 
What activity? A custom one you built?

Anyways, this is not how an Activity is meant to be used. You should not use a while loop. If you need to start an Activity and wait for the result, you need to override onActivityResult() then just start it once and wait for the result, when you get the result you can start it again. You shouldn't be launching an activity repeatedly like that in a while loop.

Activity | Android Developers

Also if the activity is something you custom built, you could look into a Service instead. Activities are generally meant to act as the user interface part of a program, not something launched repeatedly for results.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones