活动中的线程在启动另一个线程时是否会终止?
我有一个启动 3 个线程的活动 当我开始一个新活动时, “While(true)”循环
,这些线程是否会自行终止?
另一个问题,我如何开始一项新活动,但我不想允许 “后退”按钮让我返回到旧的活动 - 实际上我想处理第一个活动并创建并显示一个新的活动
谢谢 罗恩
I have an activity that starts 3 threads that make a
"While(true)" loop
when i start a new activity, does those threads terminate themselves?
And another question, how do i start a new activity but i don't want to allow
the 'back' button to return me to the old activity -
actually i want to dispose the first activity and create and show a new one
thank you
Ron
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,他们没有。您必须在结束活动之前阻止它们。
只需在启动第二个活动时从第一个活动中调用 finish() :
No, they don't. You have to stop them before closing your activity.
Just call finish() from your first activity when you start the second one :
当活动暂停或停止时,线程可能不会立即停止。更好的策略是在 onPause 或 stop 被调用时立即将一个标志设置为 false。
线程检查此标志并中断自身或退出 run 方法。
如果您不希望后退按钮显示较旧的 Activity,可以对较旧的 Activity 使用 NO_HISTORY 标志 http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NO_HISTORY
如果您想将此 Activity 作为堆栈中的第一个活动使用此标志 FLAG_ACTIVITY_TASK_ON_HOME
When activity pauses or stops Threads might not be stopped immediately. Better strategy is to have a flag which is set to false as soon as onPause or stop is called.
Threads check for this flag and interrupt themselves or come out of run method.
If you don't want back button to show older Activity, you can use NO_HISTORY flag for the older activity http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NO_HISTORY
If you want to have this activity as the first activity in the stack use this flag FLAG_ACTIVITY_TASK_ON_HOME