故意强制 android 等待并在后台加载某些内容

发布于 2024-11-27 18:07:55 字数 148 浏览 0 评论 0原文

我想强制 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼趣 2024-12-04 18:07:55
public class yourActivity extends Activity{
final WebView yourWebview; //this is the webview
Context mContext = this;

public void onCreate(Bundle B){
setContentView(R.id.somethingtoshow);//this will be shown while webview working

Runnable yourRun = new Runnable(){
public void run(){
yourWebview = new WebView(mContext);
//do whatever you want with it
//loadUrl and whatever you want

//when your done
runOnUiThread(new Runnable(){
public void run(){
setContentView(yourWebView);
}
});

}
};
Thread T= new Thread(yourRun);
T.start();
}

}
public class yourActivity extends Activity{
final WebView yourWebview; //this is the webview
Context mContext = this;

public void onCreate(Bundle B){
setContentView(R.id.somethingtoshow);//this will be shown while webview working

Runnable yourRun = new Runnable(){
public void run(){
yourWebview = new WebView(mContext);
//do whatever you want with it
//loadUrl and whatever you want

//when your done
runOnUiThread(new Runnable(){
public void run(){
setContentView(yourWebView);
}
});

}
};
Thread T= new Thread(yourRun);
T.start();
}

}
太傻旳人生 2024-12-04 18:07:55

“等待”意味着将线程置于挂起状态 - 您的意思是让应用程序在进程完成之前不执行任何操作吗?

您永远不想让主事件线程挂起或等待,这会让用户认为应用程序已冻结。为了执行您想要的操作,您可能会生成一个异步线程,从主活动加载页面。该活动将继续显示您上次执行的任何操作,并且在异步在后台进行时不会挂起或冻结。然而,用户仍然可以按下按钮,这可能会让你感到困惑。

因此,为了使应用程序显示为解冻并允许在后台发生进程,您将需要进入某些加载屏幕或限制用户在主布局上的选项。这将允许活动继续发生,但给用户带来流畅的体验。

'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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文