zoukankan      html  css  js  c++  java
  • 杂记

    1. Activity启动模式

      (1)standard

        默认模式,每启动一个都会在任务栈中创建一个,back键会依次从栈中退出。

      (2)singleTop

        如果要启动的Activity在栈顶,则不会重新创建。

      (3)singleTask

        任务栈中没有这个Activity,则会在任务栈中创建一个实例,如果任务栈中已经存在,则会将任务栈中的此activity之上的activity全部出栈,然后调用此activity的onNewIntent.

      (4)singleInstance

        只有一个实例,运行于独立的task

    2.layout_gravity 和 gravity

       android:gravity : 限定View的内容的位置,针对子布局

       android:layout_gravity  相对于父布局的位置。

    3.时间管理:

      (1)进程切换非常昂贵,避免多任务,保持单进程。

      (2)研究表明,集中注意力、高效工作,每天最多4小时。

      (3)划分任务的优先级,不要把'急切'当作'重要'。

      (4)起床后,不要查看邮件和微信。

      (5)避免开会,因为人类已知的最浪费时间的事情,就是开会。

      (6)早晨4点起床,到了中午,你就完成了一天的任务。

      (7)你没空时不会做的事情,有空了也不会做。  (世上并没有拖延症,只是不想做而已。如果可能,应该尽早放弃你没有意愿去做的那些事。而那些没有时间也会去做的事,才是你应该全力以赴的人生方向。完全赞同,没时间永远是借口)

    4.Android ConditionVariable:

      ConditionVariable用于线程同步,相当于wait(),但是更方便简单

      有三个方法: block() open() close()     

     1     public void block()
     2     {
     3         synchronized (this) {
     4             while (!mCondition) {
     5                 try {
     6                     this.wait();
     7                 }
     8                 catch (InterruptedException e) {
     9                 }
    10             }
    11         }
    12     }
    13 
    14     public void open()
    15     {
    16         synchronized (this) {
    17             boolean old = mCondition;
    18             mCondition = true;
    19             if (!old) {
    20                 this.notifyAll();
    21             }
    22         }
    23     }
    24 
    25     public void close()
    26     {
    27         synchronized (this) {
    28             mCondition = false;
    29         }
    30     }
    View Code

      从源码中可以看到,其实也是通过wait实现的,有一点需要注意 open过之后,只有close了,才能block住。

    5.back键将应用放到后台,不退出

      复写onBackPressed()方法, 调用Activity的 moveTaskToBack()方法 即可。

    6. Android ClassLoader

      PathClassLoader 只能操作dex文件

      DexClassLoader 能加载外部apk,jar,dex

    7.主线程的Looper的创建

      主线程的Looper是在ActivityThread的main()方法中种创建的。  

     1     ActivityThread.java
     2           
     3     public static void main(String[] args) {
     4         ......
     5         Looper.prepareMainLooper();
     6         ......
     7     }    
     8 
     9     Looper.java
    10     
    11     public static void prepareMainLooper() {
    12         prepare(false);
    13         synchronized (Looper.class) {
    14             if (sMainLooper != null) {
    15                 throw new IllegalStateException("The main Looper has already been prepared.");
    16             }
    17             sMainLooper = myLooper();
    18         }
    19     }

     8.创建一个圆形图片:

     1     protected void onCreate(Bundle savedInstanceState) {
     2         super.onCreate(savedInstanceState);
     3         setContentView(R.layout.activity_main);
     4         mImageView = (ImageView) findViewById(R.id.mImageView);
     5         Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.haha1);
     6         Bitmap s = createCircleBitmap(b);
     7         Drawable drawable = new BitmapDrawable(s);
     8         mImageView.setBackgroundDrawable(drawable);
     9     }
    10 
    11     
    12     @SuppressLint("ResourceAsColor")
    13     public Bitmap createCircleBitmap (Bitmap source) {
    14         Paint p = new Paint();
    15         p.setAntiAlias(true);
    16         int min = source.getWidth() > source.getHeight() ? source.getHeight() : source.getWidth();
    17         
    18         Bitmap target = Bitmap.createBitmap(min, min , Config.ARGB_8888);
    19         
    20         Canvas canvas = new Canvas(target);
    21         canvas.drawCircle(min/2, min/2, min/2, p);
    22         p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    23         canvas.drawBitmap(source, 0, 0, p);
    24         return target;
    25     }

      p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); 最主要的是这句,通过相互之前的一个遮盖关系实现。

    9.PowerFramework 框架

    PowerFramework是一款几乎囊括了所有Android基础功能的框架应用,这个框架目前是开源的,开发者可以在这个框架的基础上进行二次开发。结合开发者自己的UI设计,可以很快就能开发出具备基础应用功能的Android应用。

    框架和DEMO文件下载地址  http://www.ideayapai.com/Application/Home/View/default/PowerFamily/index-2.htm

    10.设置屏幕亮度:   

      通过设置Window的参数来控制。

    1                 Window w = getWindow();
    2                 WindowManager.LayoutParams wl = w.getAttributes();
    3                 wl.screenBrightness = (float)progress / 100;             // progress是seekBar的滑动的变化值
    4                 if (wl.screenBrightness < 0.1f) wl.screenBrightness = 0.1f;    // 最好能在这做一下限制,不同厂商对屏幕亮度调到最小时显示有差异,有的可能直接就黑屏
    5                 if (wl.screenBrightness > 1.0f) wl.screenBrightness = 1.0f;      
    6                 w.setAttributes(wl);

     11.自定义Notification

          NotificationCompat.Builder b = new NotificationCompat.Builder(this);
             RemoteViews remoteView = new RemoteViews(getPackageName(),
                            R.layout.notify_remoteview);
             remoteView.setTextViewText(R.id.MusicName,"MusicName");
             remoteView.setImageViewResource(R.id.ImageV,R.mipmap.ic_launcher);
             remoteView.setTextViewText(R.id.geci,"光辉岁月");
             b.setContent(remoteView)
                  .setSmallIcon(R.drawable.ic_launcher);
             Notification notification = b.build();
             notification.flags = Notification.FLAG_AUTO_CANCEL;
             NM.notify(1,notification);

       通知不显示出来:解决办法,clean project 一下,就Ok. 记得一定要设置Icon,不然不生效。  

    12 DecorView 

         private final class DecorView extends FrameLayout

       DecorView继承自FrameLayout, 是PhoneWindow 的内部类,是Window的顶层View

    13 ApplicationThread 是 ActivityThread的内部类, 启动activity的时候,会调用ApplicationThread的scheduleLaunchActivity()方法,里面通过Handler发

    消息启动Activity

      ApplicationThread 继承自ApplicationThreadNative,ApplicationThreadNative继承自Binder

  • 相关阅读:
    html php插入百度地图定位
    thinkphp验证功能(部分)
    thinkphp用ajax注册及检测个人见解
    文件系统处理_下
    文件系统处理
    jQuery ajax
    jquery(复选框全选)
    jquery(鼠标)
    找房子(数据库应用)
    php基础题
  • 原文地址:https://www.cnblogs.com/xiaojianli/p/5645116.html
Copyright © 2011-2022 走看看