【整理一点资料】 Andorid的进程和线程模型
最近在看韩国人写的Android书籍,里面讲了通电后, Android首先启动init主进程, 然后init主进程,分析init.rc文件,启动Android系统的核心进程。
接下来,init主进程启动Zygote进程, Zygote进程负责为每一个启动出来的App,生成和加载虚拟机,运行App。
接下来就是进程和线程模型, 贴一些资料如下:


public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); editText = (EditText) findViewById(R.id.weather_city_edit); Button button = (Button) findViewById(R.id.goQuery); button.setOnClickListener(this); Looper looper = Looper.myLooper(); //得到当前线程的Looper实例,由于当前线程是UI线程也可以通过Looper.getMainLooper()得到 messageHandler = new MessageHandler(looper); //此处甚至可以不需要设置Looper,因为 Handler默认就使用当前线程的Looper } public void onClick(View v) { new Thread() { public void run() { Message message = Message.obtain(); message.obj = "abc"; messageHandler.sendMessage(message); //发送消息 } }.start(); } Handler messageHandler = new Handler { public MessageHandler(Looper looper) { super(looper); } public void handleMessage(Message msg) { setTitle((String) msg.obj); } }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); editText = (EditText) findViewById(R.id.weather_city_edit); Button button = (Button) findViewById(R.id.goQuery); button.setOnClickListener(this); } public void onClick(View v) { new GetWeatherTask().execute(“aaa”); } class GetWeatherTask extends AsyncTask?String, Integer, String> { protected String doInBackground(String... params) { return getWetherByCity(params[0]); } protected void onPostExecute(String result) { setTitle(result); } }