代码小结

  • 过滤器可以设置优先级:

    IntentFilter filter = new IntentFilter();
    filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
    
  • 获取随机函数

    private static int getRandom(int sumWeight) {
        return (int) Math.round(Math.random() * sumWeight);
    }
    
  • Bundle 的传值使用方法:

    Bundle bundle = new Bundle();
    bundle.putString("a", "sub");
    bundle.putString("b", "let");
    
    Intent intent = new Intent(this, activityA.class);
    intent.putExtra("all", bundle);
    startActivity(intent);
    
  • 代码设置屏幕竖屏:

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    
  • 设置延时的handler:

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            DaemonServiceManager.startDaemonService(LauncherActivity.this);
            startMainActivity(true);
            handler.sendEmptyMessageDelayed(FINISH_WHAT, FINISH_INTERVAL_TIME);
        }
    }, intervalTime);
    
  • 在Android里面

    view = new ImageView(context);
    view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    view.setBackgroundResource(R.drawerable.**);
    

中,资源文件只能是图片等资源文件,布局文件是不能这样写的,如果要嵌入布局,如下:

view =  View.inflate(Context context, R.layout.**, null);