一、类
1.1基础BasicActivity需要继承AppCompatActivity和实现PosViewLoad接口
PosViewLoad接口如下所示:
public interface PosViewLoad {
void onBeforeViewLoad(BasicActivity activity,int resId);
void onAfterViewLoad(BasicActivity activity,int resId);
}
onBeforeViewLoad表示Activity加载前的回调
onAfterViewLoad表示加载后的回调
1.2Bundle SavedInstance冷却包的处理
protected void defSaveInstanceState(Bundle outState){
try{
Log.d("PPOSX", "defSaveInstanceState do.... on "+this.getClass().getName());
Field[] fields=this.getClass().getDeclaredFields();
for(Field f:fields){
PosSerializableFlag psf=f.getAnnotation(PosSerializableFlag.class);
if(psf!=null){
f.setAccessible(true);
Object obj=f.get(this);
if(obj!=null) {
String sav_key = this.getClass().getName().replace('.', '$') + "$" + f.getName();
if (obj instanceof Integer) {
outState.putInt(sav_key, (Integer) obj);
} else if (obj instanceof Double) {
outState.putDouble(sav_key, (Double) obj);
} else if (obj instanceof Long) {
outState.putLong(sav_key, (Long) obj);
} else if (obj instanceof String) {
outState.putString(sav_key, obj.toString());
} else {
outState.putSerializable(sav_key, (Serializable) obj);
}
}
}
}
}catch (Exception ex){
PosUtil.tryError(ex);
}
}
Activity中有@PosSerializableFlag 注解的属性,程序就会把值存放到冷却包处理。