今天下午花了點(diǎn)時(shí)間來(lái)體驗(yàn)Android,本以為5分鐘就可以完成的Helloworld,卻用了將近1個(gè)半小時(shí)的時(shí)間,實(shí)在有些不爽。現(xiàn)在暫時(shí)記下一些不爽的地方,希望大家能指出問(wèn)題在哪里?有什么更好的辦法?
前面按照文檔,下載sdk和eclipse plugin,安裝配置安裝文檔一路順風(fēng)。馬上新建工程,編寫(xiě)Helloworld代碼,啟動(dòng)運(yùn)行。想著應(yīng)該大工告成,看的到效果收工了。誰(shuí)知道問(wèn)題出來(lái)了。
代碼如下:
package person.pengjun.hello;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
TextView tv = new TextView(this);
tv.setText("過(guò)河卒, 每天進(jìn)步1%");
setContentView(tv);
}
}
不爽1:HelloWorld需啟動(dòng)兩次
在Eclipse的run菜單里面配置了Android Appliaction的運(yùn)行配置,一切OK,啟動(dòng)工程。一切啟動(dòng)正常,按照文檔的說(shuō)發(fā),我就應(yīng)該能夠看到屏幕中顯示出來(lái)的“過(guò)河卒,每天進(jìn)步1%”的字樣了。而我實(shí)踐看到的確實(shí)手機(jī)桌面,不解。在手機(jī)菜單里面找了好幾遍也沒(méi)有找到相應(yīng)的啟動(dòng)選項(xiàng)。(PS:到時(shí)里面的API DEMO吸引我看了好久)。沒(méi)辦法,沒(méi)看到效果。只好回頭檢查是否有錯(cuò)誤。
發(fā)現(xiàn)Eclipse里面的啟動(dòng)信息如下:
[2007-11-19 18:10:52 - HelloAndroid] ------------------------------
[2007-11-19 18:10:52 - HelloAndroid] Android Launch!
[2007-11-19 18:10:52 - HelloAndroid] Launching: person.pengjun.hello.HelloAndroid
[2007-11-19 18:10:52 - HelloAndroid] Launching the emulator.
回想doc里面說(shuō)的,啟動(dòng)會(huì)先啟動(dòng)emulator,之后才會(huì)啟動(dòng)application。
看到這里,我又Ctrl+F11再啟動(dòng)了一次Android Application,結(jié)果挺好。終于出現(xiàn)了,我希望看到的界面。
啟動(dòng)信息如下:
[2007-11-19 18:12:30 - HelloAndroid] ------------------------------
[2007-11-19 18:12:30 - HelloAndroid] Android Launch!
[2007-11-19 18:12:31 - HelloAndroid] Launching: person.pengjun.hello.HelloAndroid
[2007-11-19 18:12:31 - HelloAndroid] Pushing HelloAndroid.apk to /data/app on the device
[2007-11-19 18:12:31 - HelloAndroid] Starting activity on device: person.pengjun.hello.HelloAndroid
[2007-11-19 18:12:33 - HelloAndroid] ActivityManager: Starting: Intent { comp={person.pengjun.hello/person.pengjun.hello.HelloAndroid} }
雖然這沒(méi)有浪費(fèi)我什么時(shí)間,但是文檔里面居然一個(gè)字也沒(méi)有提。不爽。
不爽2:修改居然不會(huì)自動(dòng)更新
看到效果了,心里面也不免小興奮一把。修改了“過(guò)河卒,每天進(jìn)步1%”為“Android,I love you”以表慶祝。啟動(dòng)運(yùn)行,問(wèn)題還是依舊,看到的還就手機(jī)桌面,心里面不免暗暗嘆息。再次Ctrl+F11,這回出來(lái)了。但是出來(lái)了的字符讓我傷心,居然還是“過(guò)河卒,,每天進(jìn)步1%”,這有點(diǎn)受不了了。嘗試關(guān)閉程序再次嘗試,問(wèn)題依舊。于是想是不是和Web瀏覽器的緩存一樣,那有記錄下來(lái)了。于是查找一番,果然讓我查到了,在手機(jī)桌面的Application里面出現(xiàn)了 我的AndroidApplication,啟動(dòng)依然是“過(guò)河卒,每天進(jìn)步1%”。
沒(méi)辦法只好查文檔了,折騰了一會(huì),終于讓我查到。
http://code.google.com/android/reference/emulator.html#controlling
里面有這樣的記錄:
Only the first emulator instance can preserve user data across sessions. It stores the user data in a file — by default, it stores the data in the file ~/.android/userdata.img (on Linux and Mac)
or C:\Documents and Settings\<user>\Local Settings\Android\userdata.img
(on Windows) in your development computer. You can control the storage (and loading) location of the user data file by using the -data
option when starting the emulator 。
原來(lái)在這里C:\Documents and Settings\<user>\Local Settings\Android\userdata.img
去到這里,發(fā)現(xiàn)什么也沒(méi)有。不甘心,查找了一下。原來(lái)它在C:\Documents and Settings\<user>\Local Settings\Application Data\Android\userdata.img 。找到它,毫不客氣刪除重運(yùn)AndroidApplication,終于見(jiàn)到“Android,I love you”。看來(lái)還是那句歌唱的好啊,“想說(shuō)愛(ài)你不容易”。
找到問(wèn)題經(jīng)過(guò)多次嘗試,仍然不會(huì)自動(dòng)隨修改更新,心里面很是不爽啊。每次修改只好刪除,userdata.img再試,實(shí)在麻煩。不過(guò)暫時(shí)也沒(méi)有更好的辦法,只好如此。
由于默認(rèn)目錄太偏,而且會(huì)影響所有的Android的運(yùn)行,所以想了個(gè)替代的辦法。在Eclipse的run菜單里面配置emulator的啟動(dòng)配置。在工程文件下面建一個(gè)data文件夾,把這個(gè)user data file 指定到這個(gè)位置上面。這樣每個(gè)Application都配置的話相互之間也就不會(huì)影響了。配置如下圖,
不管配置的多好,總之還是那個(gè)詞,不爽。
上面是我今天初用Android遇到的問(wèn)題,這可能和我機(jī)器的運(yùn)行環(huán)境有關(guān)系。不知道大家是否也有遇到,不知道大家是否有更好好的處理辦法? 請(qǐng)大家多多指點(diǎn)。
11月20日晨
早上換了臺(tái)機(jī)器,重新解壓了個(gè)eclipse,版本3.3.再次嘗試HelloAndroid,居然上面的問(wèn)題,一個(gè)也沒(méi)有出現(xiàn)。這可能和系統(tǒng)的環(huán)境有關(guān)
系。因?yàn)樽蛱斓哪桥_(tái)機(jī)器上面東西比較雜,也疏于打理。具體是什么方面的影響還不清楚,不過(guò)昨天機(jī)器的Eclipse是3.1的版本。
平凡而簡(jiǎn)單的人一個(gè),無(wú)權(quán)無(wú)勢(shì)也無(wú)牽無(wú)掛。一路廝殺,只進(jìn)不退,死而后已,豈不爽哉!
收起對(duì)“車(chē)”日行千里的羨慕;收起對(duì)“馬”左右逢緣的感嘆;目標(biāo)記在心里面,向前進(jìn)。一次一步,一步一腳印,跬步千里。
這個(gè)角色很適合現(xiàn)在的我。
posted on 2007-11-19 19:21
過(guò)河卒 閱讀(9282)
評(píng)論(5) 編輯 收藏 所屬分類(lèi):
Android/gPhone