Starting activity in a loop

  1. skill_

    skill_ New Member

    The problem is following:
    I need to run an activity again and again analysing results, until results match some conditions.
    So I use
    Code (Text):
    1. while(...)
    2. {
    3. ...
    4. StartActivityForResult(...); //Activity is not launched here
    5. ...
    6. }
    So I wonder how can I run an activity in a loop, and where and how should I analyse results.

  2. alostpacket

    alostpacket Over Macho Grande? VIP Member

    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.
  3. skill_

    skill_ New Member

    Result is something user inputs. So this must be an Activity to provide results.
    Finally I came up with launching activity againg from onActivityResult() if results dont match conditions.

Share This Page