gpt4 book ai didi

android - 在开始 Activity 之前等待 ContentProvider 加载

转载 作者:行者123 更新时间:2023-11-30 01:10:15 25 4
gpt4 key购买 nike

在开始特定 Activity 之前,我可以使用什么技术来等待我的 ContentProvider 填满?我正在使用 SyncAdapter 加载 ContentProvider。

通常我不想阻止我的用户界面。但是我的应用程序是一个数据应用程序,数据来自远程服务器;它从那里保存在我的 ContentProvider (sqlite db) 中。所以我向用户展示了一个 SplashActivity。我希望在将用户带到 MainActivity 之前加载内容提供程序。我怎么做?同样,我的应用是 SplashActivity -> MainActivity

最佳答案

您可以使用 AsyncTask

喜欢:

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {

//MAKE YOUR REQUEST HERE
protected Long doInBackground(URL... urls) {
int count = urls.length;
long totalSize = 0;
for (int i = 0; i < count; i++) {
totalSize += Downloader.downloadFile(urls[i]);
publishProgress((int) ((i / (float) count) * 100));
// Escape early if cancel() is called
if (isCancelled()) break;
}
return totalSize;
}

protected void onProgressUpdate(Integer... progress) {
setProgressPercent(progress[0]);
}

//When finish the request CALL MainActivity HERE
protected void onPostExecute(Long result) {
showDialog("Downloaded " + result + " bytes");
}
}

或者使用 Volley library

关于android - 在开始 Activity 之前等待 ContentProvider 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38493209/

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