自定义BaseActivity,封装一些操作。
public abstract class BaseActivity extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityController.addActivty(this);
}
//以类名开启activity
protected void openActivity(Class<?> mClass) {
openActivity(mClass, null);
}
protected void openActivity(Class<?> mClass, Bundle bundle) {
Intent intent=new Intent(this,mClass);
if(bundle!=null){
intent.putExtras(bundle);
}
startActivity(intent);
}
//以action开启activity
protected void actionActivity(String action){
actionActivity(action, null);
}
protected void actionActivity(String action,Bundle bundle){
Intent intent=new Intent(action);
if(bundle!=null){
intent.putExtras(bundle);
}
startActivity(intent);
}
//以类名开启activity
protected <T> void startActivity(Class<T> mClass){
Intent intent=new Intent(this,mClass);
startActivity(intent);
}
// 初始化控件
public abstract void initView();
@Override
protected void onDestroy() {
ActivityController.removeActivity(this);
super.onDestroy();
}
}
转载于:https://my.oschina.net/u/2406195/blog/552414