我执行异步任务时出现黑屏。应用程序显示需要30-40秒。直到那时有一个黑屏,我怎么能解决它? 我看到需要很长时间的主要方法是从亚马逊S3下载对象并解压缩。
//AsyncTasks 2
class secondAsyncTask extends AsyncTask<String, String, Boolean> {
Data newData = null;
public String LOCAL_PATH = null;
public secondAsyncTask(Data data) {
newData = data;
LOCAL_PATH = newData.context.getFilesDir().getPath().toString() ;
}
@Override
protected Boolean doInBackground(String... params) {
String fileName = newData.versionString + "_" + newData.timestampValue ;
String KEY = fileName+ ".js" ;
String KEY_ZIP = fileName + ".zip" ;
String BUCKET_NAME = "galateajs" ;
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
newData.context,
"eu-west-1:3ad5de52-dfab-439f-96b1-8ebda", // Identity Pool ID
Regions.EU_WEST_1 // Region
);
AmazonS3Client s3Client = new AmazonS3Client(credentialsProvider);
File localFile = new File(LOCAL_PATH +"/dataFile.txt");
File localFile_zip = new File(LOCAL_PATH +"/images.zip");
//###
// write to file
try {
ObjectMetadata object = s3Client.getObject(new GetObjectRequest(BUCKET_NAME, KEY), localFile);
try {
newData.setPrefrence("timestamp", newData.timestampValue);//set new timestamp
JSONObject objTmp = newData.readFromFile("dataFile.txt");// get new local file
newData.updateJsonString(objTmp.toString());//update global var
} catch (Exception e) {
e.printStackTrace();
}
newData.deleteImages(LOCAL_PATH + "/");
newData.logFiles(LOCAL_PATH + "/");
//download images
ObjectMetadata object_zip = s3Client.getObject(new GetObjectRequest(BUCKET_NAME, KEY_ZIP), localFile_zip);
System.out.println("File Downloaded: " + object_zip);
newData.unpackZip(LOCAL_PATH + "/", "images.zip");
} catch (AmazonServiceException e) {
System.out.println("Error Message: " + e.getMessage());
System.out.println("HTTP Status Code: " + e.getStatusCode());
System.out.println("AWS Error Code: " + e.getErrorCode());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Boolean aBoolean) {
try {
JSONObject objTmp = newData.readFromFile("dataFile.txt");
newData.updateJsonString(objTmp.toString());
Splash.notificationManager.cancel(Splash.notifyId);
Toast.makeText(Splash.context,"Boat Saver data updated successfully!",Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
super.onPostExecute(aBoolean);
}
我该如何解决这个问题?