我有一个包含按钮的活动,当您按下按钮时,它会加载第二个活动。第二个活动有一个 listView 和一堆其他东西,在大多数设备上加载需要几秒钟,所以我想显示一个 progressDialog 让用户知道活动实际上正在加载。我有以下内容:
编辑:
public void rewardFirstNext(View view){
AsyncTask<Void, Void, Void> progress = new AsyncTask<Void, Void, Void>() {
private ProgressDialog progressDialog;
protected void onPreExecute(){
progressDialog = new ProgressDialog(getApplicationContext());
progressDialog.setTitle("Loading Installed Applications");
progressDialog.setMessage("Please wait.");
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
progressDialog.show();
}
protected Void doInBackground(Void... voids) {
PackageManager mPackageManager = getPackageManager();
List<Applications> packageInfoListApps = new ArrayList<Applications>();
List<PackageInfo> packageInfoList = mPackageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
List<PackageInfo> installedApps = new ArrayList<PackageInfo>();
for (PackageInfo apps : packageInfoList) {
if (!isSystemPackage(apps)) {
installedApps.add(apps);
}
}
Collections.sort(installedApps, new Comparator<PackageInfo>() {
public int compare(PackageInfo o1, PackageInfo o2) {
return o1.applicationInfo.loadLabel(getPackageManager()).toString().compareToIgnoreCase(o2.applicationInfo.loadLabel(getPackageManager()).toString());
}
});
for (PackageInfo apps : installedApps) {
packageInfoListApps.add(new Applications(apps, false, false));
}
//what else happens here?
return null;
}
protected void onPostExecute(Void result){
progressDialog.dismiss();
}
};
progress.execute((Void[]) null);
}