Coder Social home page Coder Social logo

baseapp's Introduction

BaseApp

App开发基本框架 开发须知:

一、JAVA篇

  • 所有Activity请务必继承BaseActivity。
  • 避免将Activity作为Context在函数中传递,绝大多数情况下用MyApplication.getContext()替代。
  • 尽量减少内部类的使用(一般内部类会对外部类有引用)。
  • 所有Log打印请使用LogUtil打印。
  • Toast Snackbar请尽量使用相关Utils。
  • 所有for循环请使用 int size = size(); for (int i = 0, i < size, i++) {}结构。
  • 尽量避免使用+做String拼接。
  • 在Activity的onDestroy()方法中反注册掉监听器、释放Handler。
  • 不要使用死循环发送网络请求:)
  • 将耗时任务从main线程移除到其他线程。

二、Res篇

  • Layout视图尽量使用RelativeLayout,减少视图层级嵌套,方便后期修改,如无必要请使用FrameLayout、LinearLayou等简单布局。
  • 尽可能不要在RelativeLayout中嵌套带内部View带weight的LinearLayout。
  • 对于重复使用的属性请抽象到styles中,命名请使用common、视图或逻辑作为前缀。
  • 其他相关资源如果android:XXX中有就不要再私自定义。如: color balck, color white。
  • 图片请使用tinypng进行压缩。
  • 定义res前请检查是否已有相关资源,避免重复定义。

三、libs篇

四、优化篇

  • 过度绘制(开发者选项 显示过度绘制)。

  • 内存泄露(Android Studio -> Analysis Tasks)。

  • 电池优化。

  • CPU使用(Profile)。

    请查看光头哥捣蛋弟相关视频Udacity 性能优化,优化文章精选

五、常用网站篇

   菜鸟工具开发工具图片压缩

六、范例篇

Activity范例


public class LogoActivity extends BaseActivity {
	public static final int LOGIN_SELECT = 1;
	public static final int LOGIN_SUC = 2;
	public static final int DEVICE_CHOICE = 3;
	public static final int UPDATE = 4;
// 不要过度使用static、final
 Handler mHandler = new Handler() {  
		public void handleMessage(Message msg) {
			finish();
	 	};
};
private CountDownTimer timer = new CountDownTimer(6 * 1000, 1 * 1000) {
		@Override
		public void onTick(long millisUntilFinished) {
		}
		@Override
		public void onFinish() {
			showToast("连接超时请稍后重试");
			finish();
		}
};		
private AnimatorSet animSet = new AnimatorSet();
animSet.addListener(new AnimatorListener() {
		@Override
		public void onAnimationStart(com.nineoldandroids.animation.Animator animation) {
		iconFace.setEnabled(false);
		}
		@Override
		public void onAnimationRepeat(com.nineoldandroids.animation.Animator animation) {
		}
		@Override
		public void onAnimationEnd(com.nineoldandroids.animation.Animator animation) {
		iconFace.setEnabled(true);
		}
		@Override
		public void onAnimationCancel(com.nineoldandroids.animation.Animator animation) {
		}
});
	@Override
	public void finish() {
// 注销		
		timer.cancel();
// 清空		
		mHandler.removeCallbacksAndMessages(null);
// 反注册
  		animSet.removeAllListeners();
		super.finish();
	}
}

 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.