Framework 学习笔记

本文详细解析JNI(Java Native Interface)在Android开发中的应用,包括内部目录结构、关键函数调用流程以及如何实现跨语言调用。同时,阐述了Android进程中Linux用户ID的分配机制、组件类型及其优先级,以及Android线程模型与UI线程操作的限制。最后,提供在工作线程中更新UI状态的最佳实践,如使用AsyncTask等方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JNI:

http://blog.youkuaiyun.com/droidpioneer/article/details/6787571

其中的目录:

internal目录:\frameworks\base\core\java\com\android\internal\os
RegFNIRec gRegJNI[]数组对应的函数在:\frameworks\base\core\jni
jniRegisterNativeMethods函数在:\dalvik\libnativehelper\JNIHelp.c中调用RegisterNatives 在\dalvik\vm\Jni.c中

android进程:

the system assigns each application a unique Linux user ID。每个应用程序有一个Linux user ID

Each process has its own virtual machine (VM), so an application's code runs in isolation from other applications.

Android starts the process when any of the application's components need to be executed

android component:

Each component is a different point through which the system can enter your application。they areActivities、ServicesContent providersBroadcast receivers。

android process 五类按优先级排列:

Foreground processVisible processService process Background process Empty process

android线程:

When an application is launched, the system creates a thread of execution for the application, called "main.",alse called UI thread.The system doesnotcreate a separate thread for each instance of a component(android component). All components that run in the same process are instantiated in the UI thread, and system calls to each component are dispatched from that thread.Consequently, methods that respond to system callbacks (such asonKeyDown()to report user actions or a lifecycle callback method) always run in the UI thread of the process.

the Andoid UI toolkit isnotthread-safe(components from theandroid.widgetandandroid.viewpackages). So, you must not manipulate your UI from a worker thread—you must do all manipulation to your user interface from the UI thread. Thus, there are simply two rules to Android's single thread model:

  1. Do not block the UI thread
  2. Do not access the Android UI toolkit from outside the UI thread
在工作线程中可以用:

修改UI线程中控件的状态,最好的方法是用AsyncTask


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值