涉及的類
AppStart //歡迎頁面
MainActivity //主頁面
LogUploadService //上傳日誌的服務
TDevice //手機設備工具類
功能介紹
1.設置視圖,並且讓視圖做Alpha動畫
2.監聽動畫,在動畫播放完成之後,開啓服務上傳日誌,並且跳轉到MainActivity
3.在onResume方法中讓本地緩存版本與現在的版本進行比較,如果現在的版本大於緩存的版本,則清除圖片緩存
具體代碼分析
1.設置視圖,監聽動畫
// 防止第三方跳轉時出現雙實例
Activity aty=AppManager.getActivity(MainActivity.class);
if (aty != null && !aty.isFinishing()) {
finish();
}
// SystemTool.gc(this); //針對性能好的手機使用,加快應用相應速度
final View view = View.inflate(this, R.layout.app_start, null);
setContentView(view);
// 漸變展示啓動屏
AlphaAnimation aa = new AlphaAnimation(0.5f, 1.0f);
aa.setDuration(800);
view.startAnimation(aa);
aa.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation arg0) {
redirectTo();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
});
2.在動畫結束後,進行跳轉與上傳日誌 redirectTo()
/**
* 跳轉到...
*/
private void redirectTo() {
Intent uploadLog = new Intent(this, LogUploadService.class);
startService(uploadLog);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
3.在onResume方法中讓本地緩存版本與現在的版本進行比較,如果現在的版本大於緩存的版本,則清除圖片緩存
@Override
protected void onResume() {
super.onResume();
int cacheVersion = PreferenceHelper.readInt(this, "first_install","first_install", -1);
int currentVersion = TDevice.getVersionCode();
if (cacheVersion < currentVersion) {
PreferenceHelper.write(this, "first_install", "first_install",currentVersion);
cleanImageCache(); //清除圖片緩存
}
}
4.清除圖片緩存方法 cleanImageCache()
private void cleanImageCache() {
final File folder = FileUtils.getSaveFolder("OSChina/imagecache");
File[] files = folder.listFiles();
if (files != null && files.length > 0) {
KJAsyncTask.execute(new Runnable() {
@Override
public void run() {
if (folder.isDirectory()) {
for (File file : folder.listFiles()) {
file.delete();
}
}
}
});
}
}