简体   繁体   English

Android:暂停FOR循环以等待startActivityForResult调用的子活动完成()

[英]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. 但是for循环在显示任何活动之前已运行并完成。 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. 但是..相应地使用Handle.postDelayed(new Runnable(){.//您在run method()中的代码.....},(时间限制,例如2000))。希望这会对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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