Solarex's Blog

我只想过,平平淡淡的生活,欲望啊,请放过脆弱的我

在Mac下进行JNI开发

| Comments

本文主要讲述如何在Mac开发环境下进行JNI开发。

首先编写好Java文件,示例程序主要示范了Java访问C,C访问Java静态与非静态域。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class HelloJni{
    static{
        System.loadLibrary("HelloJni");
    }
    public native static String getStringFromCStatic();
    public native String getStringFromCNonStatic();
    public String key = "key";
    public static int count = 5;
    public native String accessField();
    public native void accessStaticField();
    public static void main(String[] args){
        System.out.println(getStringFromCStatic());
        HelloJni hello = new HelloJni();
        System.out.println(hello.getStringFromCNonStatic());
        System.out.println("change before key: " + hello.key);
        hello.accessField();
        System.out.println("change after key: " + hello.key);
        System.out.println("change before count: " + count);
        hello.accessStaticField();
        System.out.println("change after count: " + count);
    }
}

Writing Better Adapters

| Comments

Implementing adapters is one of the most frequent tasks for an Android developer. It’s the base for every list. Looking at apps, lists are the base of most apps.

The schema we follow to implement list views is often the same: a View with an adapter that holds the data. Doing this all the time can make us blind to what we are writing, even to ugly code. Even worse, we end up repeating that ugly code.

It’s time to take a close look into adapters.

RecyclerView Basics

The basic operations for RecyclerViews (but also applicable for ListView) are:

  • Creating the view and the ViewHolder that holds the view information.
  • Binding the ViewHolder to the data that the adapter holds, probably a list of model classes.

Implementing this is pretty straightforward and not much can be done wrong here.

Choreographer in Android

| Comments

Choreographer is the one which acts like a interface between application view system and lower layer display system for rendering the views.

ViewRootImpl is the ViewParent or root below which only Activity window DecorView will be attached. All the view layouts set by the activity through setContentView() will attached the DecorView whose parent is ViewRootImpl. Actually ViewRootImpl is not a View its just a ViewParent which handled and manages the View Hierarchies for displaying, handling input events etc.

The number of root views that are active in your process. Each root view is associated with a window, so this can help you identify memory leaks involving dialogs or other windows.