涉及的类
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();
}
}
}
});
}
}