Android: ° ½°¸°‚Œ...

download Android: °  ½°¸°‚Œ €¸»¾¶µ½¸µ, ¾‚¾€¾µ ½µ ‚¾€¼¾·¸‚

of 42

  • date post

    15-Jun-2015
  • Category

    Documents

  • view

    1.671
  • download

    1

Embed Size (px)

Transcript of Android: ° ½°¸°‚Œ...

  • ,

    , Google

  • UI Thread! SQLite GC:

    //

    ? , - CPU?

  • UI Thread!

  • "ANR" ,

    5 10 BroadcastReceiver

    , ""

  • "ANR" ,

    - , , ,

    (Main/UI Thread)

  • ""

    , 1, RSA, .. :

    : 5-200(!): = 100--10-- (GPRS)+HTTP+6k = 1-6 (3G)Garbage collector run -- ?

  • android.os.AsyncTaskandroid.app.IntentService:http://developer.android.com/reference

  • , - , :

    (disable) 200-500, progress bar -

  • ?

    Android 2.3 (Gingerbread): StrictMode

    , !

  • ?

    - :

    StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .build());

    log , .

  • SQLite

    , , , ( 5 60)

    EXPLAIN, EXPLAIN QUERY PLANsqlite-wrapper.pl (by bradfitz)

    http://code.google.com/p/zippy-android

  • SQLite?

    ? ? ? , SQLite -- Oracle,

  • GC/

    for (Element el: elements) { Wrapper wrapper = new Wrapper(el); wrapper.doTask(); // wrapper is deleted}

    Wrapper wrapper = new Wrapper();for (Element el: elements) { wrapper.setElement(el); wrapper.doTask(); // GC is happy!}

  • 16 (24 N1/Desire) " ", Bitmap , GC , OOME

  • Bitmap bitmap = ...(1024x768 pixels, 24bpp);

    : GC bitmap ~15, , , .

    : bitmap 2.3 24,

  • GC:

    Bitmap bitmap = ...(1024x768, 24bpp);... use it ...... when you don't need it any more:bitmap.recycle();

  • (aka joys of no JIT)

    class Item { private int x, y; public int getX() { return x; } public int getY() { return y; }}List array = new ArrayList(10^9);

    Item

  • (aka joys of no JIT)

  • (aka joys of no JIT)

    :array.get(55).getX()

    1. array , List

    2. get3. 4. ...

  • (aka joys of no JIT)

    array.get(55).getX()

    5. 55- 6. Item getX()7. getX() , ...8. x!

  • (aka joys of no JIT)

    class ItemArray { private int[] xx; private int[] yy;

    public final int getX(int idx) {...} public final int getY(int idx) {...}}

    ( )

  • (aka joys of no JIT)

    class ItemArray { private int[] xx; private int[] yy;

    public final int getX(int idx) {...} public final int getY(int idx) {...}}

    inline - final

  • (aka joys of no JIT)

    String? char' StringBuilder ( - -- ) -- builder.toString() 4Mb (== 4Mchar) -->--> 8Mb (char==2bytes) -->--> 16Mb -->--> OOME!!!

  • (aka joys of no JIT)

    , char[] String ( String char[]!) (Don't even think of using XML for your next project!)(, ...)

  • (aka joys of no JIT)

    char[] -- slice, ( ) x[i] , !

  • :http://www.eclipse.org/mat/ :Debug.dumpHprofData ("/data/data//dump.hprof");:adb pull /data/data//dump.hprofhprof_conv dump.hprof dump-conv.hprof, Eclipse!

  • CPU

    , ! ...... C++

  • Android NDK

    http://developer.android.com/sdk/ndk/index.html

    java native java-:javah -jni org.some.package.MyClass .h-

  • ,

    ()

  • NDK

    Mercator java -> native -> table, , , (std-> = 0.8, std->native=0.1)

  • http://source.android.com/( , )( )http://developer.android.com/guide/index.html( , " ")http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html (JNI)http://android-developers.blogspot.com/( )

  • !

  • backup slides

  • while(true) { Task task = queue.getTaskBlocking(); task.execute();}

  • Task task;while(true) { task = queue.getTaskBlocking(); task.execute();}

  • while(true) { Task task = queue.getTaskBlocking(); task.execute(); task = null;}

  • while(true) { Task task = queue.getTaskBlocking(); task.execute();}

  • class Magic { static private int n = 0; static public void doMagic(Object obj) { if (obj != null) n++; } static public int getMagic() { return n; }}

  • class Magic { static private int n = 0; static public void doMagic(Object obj) { if (obj != null) n++; } static public int getMagic() { return n; }}while(true) { Task task = queue.getTaskBlocking(); task.execute(); task = null; Magic.doMagic(task);}

  • ...