简体   繁体   中英

Android: Pause FOR loop to waiting for child activity called by startActivityForResult to finish()

I am trying to launch some activity one by one with this code

 for (Card c : cards) {
                    i++;
                    Intent intent = new Intent(this, OneChoiceActivity.class);
                    intent.putExtra("mode", "oneChoice");
                    intent.putExtra("cardID", c.getId());
                    intent.putExtra("totalNumber", cards.size());
                    intent.putExtra("currentNumber", i);
                    startActivityForResult(intent, 1);

                }

I want to get the intent each time the child activity is launched, do something, finish it, parent activity will wait for each child to exit, then call to next activity. But the for loop is run and complete before any activity is display. Is there a solution for it?

You could try and implement a queue to store your cards. Then you get a card from the queue, launch the intent and wait for a result. When you receive the result, you get the next element from the queue and ao on, until you process all cards. Then you continue with your flow.

Not getting you what you exactly want to ask here. but.. Use Handle.postDelayed(new Runnable(){.//your code in run method().....},(time limit eg 2000)) accordingly.hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM