gpt4 book ai didi

java - Android 在 Activity 变化时口吃

转载 作者:行者123 更新时间:2023-11-29 06:13:17 24 4
gpt4 key购买 nike

我有一个 android 异步登录到我的 web 服务,但是当任务完成并且我切换到下一个 Activity 时,出现卡顿。这很烦人,因为我的 Activity 有一个进度条(在圆形模式下),它会暂停、重新启动然后 Activity 关闭。这看起来不太好。

代码如下:

//Create the new intent.    
Intent i = new Intent();
//Set the intent to open the pin entry screen
i.setClassName("com.visualdenim.passpad", "com.visualdenim.passpad.Pin");
Bundle bun = new Bundle();
//Set the data to go in the bundle
bun.putString("login_info", args[0]);
//Put the extras into the bundle
i.putExtras(bun);
//Start the credentials list activity
startActivity(i);
//Set the pretty animation
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
//Close this activity (so the user can't access the login screen once they are logged in)
finish();

我在想;所有这些都需要在 UI 线程上执行吗?有什么方法可以加快速度吗?或者我可以停止进度条旋转以避免它再次开始吗?

谢谢,我会在正确答案上打勾!

最佳答案

将您正在做的任何事情都放在异步任务中,并将进度对话框的关闭放在类的 onPostExecute 方法中。当您尝试处理线程间通信或一个线程(这里是您的 UI 线程)负载过多时,就会发生这种卡顿。使用 Async Task,所有线程维护都由操作系统处理,从而提供最佳结果。

关于java - Android 在 Activity 变化时口吃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6007115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com