故意强制 android 等待并在后台加载某些内容
我想强制 android 等待并同时继续处理某些内容。我见过线程等待函数,但这只会让事情挂起一段时间,而实际上并没有让应用程序执行任何操作。后续进程只是简单地排队等待轮到它们。
我想强制一个过程的时间安排。这是具有等待线程和异步任务
洞察力之间的结合
I want to force android to wait AND continue processing something at the same time. I have seen the Thread wait function, but that just makes things hang for a while not actually letting the app do anything. Subsequent processes are simply queued up waiting their turn.
I want to force the timing of a process. This is kind of a combination between having a thread with a wait AND an asynctask
insight appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“等待”意味着将线程置于挂起状态 - 您的意思是让应用程序在进程完成之前不执行任何操作吗?
您永远不想让主事件线程挂起或等待,这会让用户认为应用程序已冻结。为了执行您想要的操作,您可能会生成一个异步线程,从主活动加载页面。该活动将继续显示您上次执行的任何操作,并且在异步在后台进行时不会挂起或冻结。然而,用户仍然可以按下按钮,这可能会让你感到困惑。
因此,为了使应用程序显示为解冻并允许在后台发生进程,您将需要进入某些加载屏幕或限制用户在主布局上的选项。这将允许活动继续发生,但给用户带来流畅的体验。
'Waiting' means to put the thread in a suspended state - do you mean having the app simply do nothing until the process is completed?
You never want to make the main event thread hang or wait, that will make the user think the app is frozen. To do what you are wanting, you will probably spawn an async thread that loads the page from the main activity. The activity will continue to display whatever you had it doing last, and will not hang up or freeze while the async is going in the background. However, the user will still be able to press buttons, and might mess you up.
So to get the app to appear unfrozen and allow a process to occur in the background, you will want to enter into some loading screen or limit the user's options on the main layout. This will allow activity to continue occurring but allow the user a smooth experience.