要了解在Android裡的Process和Thread一定要先了解在OS中的Process和Thread是什麼意思
以下先列出幾個Process和Thread的定義和說明:
Thread :
使用CPU的最小單元,較為輕巧的process,一個process可以產生多的thread,CPU是配給thread使用。
Thread定義
OS :
行程(英語:process),是電腦中已執行程式的實體。行程為曾經是分時系統的基本運作單位。在面向行程設計的系統(如早期的UNIX,Linux 2.4及更早的版本)中,行程是程式的基本執行實體;在面向執行緒設計的系統(如當代多數作業系統、Linux 2.6及更新的版本)中,行程本身不是基本執行單位,而是執行緒的容器 (by wiki)
Process定義
OS 裡, process和thread的差別:
*一個Process可以有多個Thread, 在這個Process下的Threads共享這個Process的資源
同一個Process內的Thread使用相同的Memory Space,但這些Thread各自擁有其Stack。換句話說,Thread能透過reference存取到相同的Object,但是local variable卻是各自獨立的。
*作業系統會根據Thread的優先權以及已經用掉的CPU時間,在不同的Thread作切換
而一個Process的Global Variable可以讓它的所有Thread共享,也就是所有Thread都可以存取同一個Process的Global Variable。而每個Thread自己也有自己的專屬Variable
有了對Process和Thread的基本認識之後, 我們再來看看Android裡的Process和Thread
來看看Android developer上的說明:
http://developer.android.com/guide/components/processes-and-threads.html
"When an application component starts and the application does not have any other components running, the Android system starts a new Linux process for the application with a single thread of execution. By default, all components of the same application run in the same process and thread (called the "main" thread). If an application component starts and there already exists a process for that application (because another component from the application exists), then the component is started within that process and uses the same thread of execution. However, you can arrange for different components in your application to run in separate processes, and you can create additional threads for any process."
當一個Application被開啟、且此Application也未執行其他元件時,Android系統會create一個新的process,這個Process是single thread,也就是說,在建立Process的同時,也建立Thread。
在預設的情況下,Application做事,會被run在相同的process和thread(main thread又稱為UI thread)
另一種情況就是,在要start Application時,已經存在這個Application的Process了。如果是這種情況,就不會在開一個Process,而是在同一個Process內執行,並且是使用相同的執行緒來執行,也就是UI thread(我的解讀是,如果原本建立好的tid只有5788這個main thread,那麼接著也會用這個tid 5788的thread來做執行)。
ticwhang
ticwhang's blog
2016年4月8日 星期五
2015年5月27日 星期三
解決 無法取得 http://archive.ubuntu.com/ubuntu/pool/main/e/eglibc/libc6-dev_2.17-0ubuntu5.1_amd64.deb,404 Not Found [IP: 91.189.92.200 80]
發生版本:
Ubuntu 12.04
發生日期:
2015/05/27 15:20
原因是因為我們的ubuntu 版本已經不再支援了...
所以在更新軟體資料時, 會抓不到相關的資訊
錯誤訊息:
autoconf autotools-dev automake libc6-dev libltdl-dev libtool
是否不經驗證就安裝這些套件?[y/N]y
錯誤 http://archive.ubuntu.com/ubuntu/ raring/main autoconf all 2.69-1ubuntu1
404 Not Found [IP: 91.189.92.200 80]
錯誤 http://archive.ubuntu.com/ubuntu/ raring/main autotools-dev all 20120608.1
404 Not Found [IP: 91.189.92.200 80]
錯誤 http://archive.ubuntu.com/ubuntu/ raring/main automake all 1:1.11.6-1ubuntu1
404 Not Found [IP: 91.189.92.200 80]
錯誤 http://archive.ubuntu.com/ubuntu/ raring/main libltdl-dev amd64 2.4.2-1.2ubuntu1
404 Not Found [IP: 91.189.92.200 80]
錯誤 http://archive.ubuntu.com/ubuntu/ raring/main libtool amd64 2.4.2-1.2ubuntu1
404 Not Found [IP: 91.189.92.200 80]
錯誤 http://archive.ubuntu.com/ubuntu/ raring-security/main libc6-dev amd64 2.17-0ubuntu5.1
404 Not Found [IP: 91.189.92.200 80]
無法取得 http://archive.ubuntu.com/ubuntu/pool/main/a/autoconf/autoconf_2.69-1ubuntu1_all.deb,404 Not Found [IP: 91.189.92.200 80]
無法取得 http://archive.ubuntu.com/ubuntu/pool/main/a/autotools-dev/autotools-dev_20120608.1_all.deb,404 Not Found [IP: 91.189.92.200 80]
無法取得 http://archive.ubuntu.com/ubuntu/pool/main/a/automake1.11/automake_1.11.6-1ubuntu1_all.deb,404 Not Found [IP: 91.189.92.200 80]
無法取得 http://archive.ubuntu.com/ubuntu/pool/main/e/eglibc/libc6-dev_2.17-0ubuntu5.1_amd64.deb,404 Not Found [IP: 91.189.92.200 80]
無法取得 http://archive.ubuntu.com/ubuntu/pool/main/libt/libtool/libltdl-dev_2.4.2-1.2ubuntu1_amd64.deb,404 Not Found [IP: 91.189.92.200 80]
無法取得 http://archive.ubuntu.com/ubuntu/pool/main/libt/libtool/libtool_2.4.2-1.2ubuntu1_amd64.deb,404 Not Found [IP: 91.189.92.200 80]
...
解法:
更新軟體的來源資訊
sudo apt-get dist-upgrade
sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
grep -E 'archive.ubuntu.com|security.ubuntu.com' /etc/apt/sources.list.d/*
sudo apt-get update
參考網站:
https://smyl.es/how-to-fix-ubuntudebian-apt-get-404-not-found-package-repository-errors-saucy-raring-quantal-oneiric-natty/?doing_wp_cron=1432713112.4604339599609375000000
Ubuntu 12.04
發生日期:
2015/05/27 15:20
原因是因為我們的ubuntu 版本已經不再支援了...
所以在更新軟體資料時, 會抓不到相關的資訊
錯誤訊息:
autoconf autotools-dev automake libc6-dev libltdl-dev libtool
是否不經驗證就安裝這些套件?[y/N]y
錯誤 http://archive.ubuntu.com/ubuntu/ raring/main autoconf all 2.69-1ubuntu1
404 Not Found [IP: 91.189.92.200 80]
錯誤 http://archive.ubuntu.com/ubuntu/ raring/main autotools-dev all 20120608.1
404 Not Found [IP: 91.189.92.200 80]
錯誤 http://archive.ubuntu.com/ubuntu/ raring/main automake all 1:1.11.6-1ubuntu1
404 Not Found [IP: 91.189.92.200 80]
錯誤 http://archive.ubuntu.com/ubuntu/ raring/main libltdl-dev amd64 2.4.2-1.2ubuntu1
404 Not Found [IP: 91.189.92.200 80]
錯誤 http://archive.ubuntu.com/ubuntu/ raring/main libtool amd64 2.4.2-1.2ubuntu1
404 Not Found [IP: 91.189.92.200 80]
錯誤 http://archive.ubuntu.com/ubuntu/ raring-security/main libc6-dev amd64 2.17-0ubuntu5.1
404 Not Found [IP: 91.189.92.200 80]
無法取得 http://archive.ubuntu.com/ubuntu/pool/main/a/autoconf/autoconf_2.69-1ubuntu1_all.deb,404 Not Found [IP: 91.189.92.200 80]
無法取得 http://archive.ubuntu.com/ubuntu/pool/main/a/autotools-dev/autotools-dev_20120608.1_all.deb,404 Not Found [IP: 91.189.92.200 80]
無法取得 http://archive.ubuntu.com/ubuntu/pool/main/a/automake1.11/automake_1.11.6-1ubuntu1_all.deb,404 Not Found [IP: 91.189.92.200 80]
無法取得 http://archive.ubuntu.com/ubuntu/pool/main/e/eglibc/libc6-dev_2.17-0ubuntu5.1_amd64.deb,404 Not Found [IP: 91.189.92.200 80]
無法取得 http://archive.ubuntu.com/ubuntu/pool/main/libt/libtool/libltdl-dev_2.4.2-1.2ubuntu1_amd64.deb,404 Not Found [IP: 91.189.92.200 80]
無法取得 http://archive.ubuntu.com/ubuntu/pool/main/libt/libtool/libtool_2.4.2-1.2ubuntu1_amd64.deb,404 Not Found [IP: 91.189.92.200 80]
...
解法:
更新軟體的來源資訊
sudo apt-get dist-upgrade
sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
grep -E 'archive.ubuntu.com|security.ubuntu.com' /etc/apt/sources.list.d/*
sudo apt-get update
參考網站:
https://smyl.es/how-to-fix-ubuntudebian-apt-get-404-not-found-package-repository-errors-saucy-raring-quantal-oneiric-natty/?doing_wp_cron=1432713112.4604339599609375000000
2014年12月26日 星期五
介紹 Customed ArrayAdapter
ArrayAdapter在android的使用上,可說是非常廣泛,像是ListView, spinner, Menu, Dialog裡,都可以把ArrayAdapter塞進去,讓使用者看到條列式的資訊
使用時機:
我們要去實作的有:
1. 新增在LisView裡的layout : list_item_text.xml
http://developer.android.com/reference/android/widget/ArrayAdapter.html
http://windrealm.org/tutorials/android/android-listview.php
https://devtut.wordpress.com/2011/06/09/custom-arrayadapter-for-a-listview-android/
下載原始檔
使用時機:
- 我們要顯示的資料是條列式的
- 當要顯示的資料類似共通點,如:類似的UI layout,
- 要顯示的list資料量很多,無法一次顯示(如果一次顯示,performance可能會不好)
我們要去實作的有:
1. 新增在LisView裡的layout : list_item_text.xml
2. ArrayAdapter本身的實作
3. 建立ArrayAdapter並且顯示private class MyArrayAdapter extends ArrayAdapter { private ArrayList data; // The constructor of ArrayAdapter public MyArrayAdapter(Context context, int layoutResourceId, ArrayList data) { super(context, layoutResourceId); this.data = data; } // How many items are in the data set represented by this Adapter @Override public int getCount() { return data.size(); } // Get a View that displays the data at the specified position in the data set @Override public View getView(int position, View convertView, ViewGroup parent) { View view; if (convertView == null) { LayoutInflater inflater = ((Activity) this.getContext()).getLayoutInflater(); view = inflater.inflate(R.layout.list_item_text, parent, false); } else { view = convertView; } TextView text; text = (TextView) view.findViewById(R.id.rowTextView); text.setText(data.get(position)); return view; } }
參考網站:@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_array_adapter); mListView = (ListView) findViewById(R.id.mainListView); ArrayList planetList = new ArrayList (); planetList.addAll(Arrays.asList(planets) ); mListAdapter = new MyArrayAdapter(this, R.layout.list_item_text, planetList); mListView.setAdapter(mListAdapter); }
http://developer.android.com/reference/android/widget/ArrayAdapter.html
http://windrealm.org/tutorials/android/android-listview.php
https://devtut.wordpress.com/2011/06/09/custom-arrayadapter-for-a-listview-android/
下載原始檔
訂閱:
文章 (Atom)