From: http://developer.android.com/
Android applications are, at least on the T-Mobile G1, limited to 16 MB of heap. It's both a lot of memory for a phone and yet very little for what some developers want to achieve. Even if you do not plan on using all of this memory, you should use as little as possible to let other applications run without getting them killed. The more applications Android can keep in memory, the faster it will be for the user to switch between his apps. As part of my job, I ran into memory leaks issues in Android applications and they are most of the time due to the same mistake: keeping a long-lived reference to a Context.
On Android, a Context is used for many operations but mostly to load and access resources. This is why all the widgets receive a Context parameter in their constructor. In a regular Android application, you usually have two kinds of Context, Activity and Application. It's usually the first one that the developer passes to classes and methods that need a Context:
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
TextView label = new TextView(this);
label.setText("Leaks are bad");
setContentView(label);
}
This means that views have a reference to the entire activity and therefore to anything your activity is holding onto; usually the entire View hierarchy and all its resources. Therefore, if you leak the Context ("leak" meaning you keep a reference to it thus preventing the GC from collecting it), you leak a lot of memory. Leaking an entire activity can be really easy if you're not careful.
When the screen orientation changes the system will, by default, destroy the current activity and create a new one while preserving its state. In doing so, Android will reload the application's UI from the resources. Now imagine you wrote an application with a large bitmap that you don't want to load on every rotation. The easiest way to keep it around and not having to reload it on every rotation is to keep in a static field:
private static Drawable sBackground;
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
TextView label = new TextView(this);
label.setText("Leaks are bad");
if (sBackground == null) {
sBackground = getDrawable(R.drawable.large_
}
label.setBackgroundDrawable(
setContentView(label);
}
This code is very fast and also very wrong; it leaks the first activity created upon the first screen orientation change. When a Drawable is attached to a view, the view is set as a callback on the drawable. In the code snippet above, this means the drawable has a reference to the TextView which itself has a reference to the activity (the Context) which in turns has references to pretty much anything (depending on your code.)
This example is one of the simplest cases of leaking the Context and you can see how we worked around it in the Home screen's source code (look for the unbindDrawables() method) by setting the stored drawables' callbacks to null when the activity is destroyed. Interestingly enough, there are cases where you can create a chain of leaked contexts, and they are bad. They make you run out of memory rather quickly.
There are two easy ways to avoid context-related memory leaks. The most obvious one is to avoid escaping the context outside of its own scope. The example above showed the case of a static reference but inner classes and their implicit reference to the outer class can be equally dangerous. The second solution is to use the Application context. This context will live as long as your application is alive and does not depend on the activities life cycle. If you plan on keeping long-lived objects that need a context, remember the application object. You can obtain it easily by calling Context.getApplicationContext(
In summary, to avoid context-related memory leaks, remember the following:
* Do not keep long-lived references to a context-activity (a reference to an activity s
Thứ Hai, 19 tháng 4, 2010
Avoiding Memory Leaks
Thứ Năm, 8 tháng 4, 2010
Android - Killing Processes
http://developer.android.com/
Due to kernel restriction, Process.killProcess(processID) is not allowed to kill processes that they did not in the application package/system-default application like: Calculator, BrowserActivity, ...
Using:
>adb -[option d/e] shell top
to show updated running processes.
Thứ Sáu, 22 tháng 1, 2010
Android: Emulator
Using "-netdelay <delayinMs>
Thứ Tư, 30 tháng 12, 2009
Android: Native Android Action
Native Android applications allow Intents to launch Activities and Sub-Activities.
Actions list:
=> + content://contacts/people/1 -- Display information about the person whose identifier is "1".
=> + content://contacts/people/ -- Display a list of people, which the user can browse through.
=> +tel:123 -- Display the phone dialer with the given number filled in. Note how the VIEW action does what what is considered the most reasonable thing for a particular URI. => +content://contacts/people/1 -- Display the phone dialer with the person filled in.
=> +tel:123 -- Display the phone dialer with the given number filled in.
ACTION_EDITcontent://contacts/people/1 -- Edit information about the person whose identifier is "1".-
ACTION_MAINwith categoryCATEGORY_HOME-- Launch the home screen. -
ACTION_GET_CONTENTwith MIME typevnd.android.cursor.item/phone-- Display the list of people's phone numbers, allowing the user to browse through them and pick one and return it to the parent activity. -
ACTION_CALLBring up a phone dialer and immediately initiates a call using the number suplied in the data URI. In generally, it's considered better form to use the DIAL_ACTION if possible. ACTION_DELETEStart an Activity that lets you delete the entry currently stored at the URI location.ACTION_ANSWEROpen an Activity that handles incoming calls. This is handled by native phone dialer.ACTION_PICKACTION_INSERTACTION_SEARCHACTION_SENDTOACTION_SENDACTION_WEB_SEARCH
Thứ Ba, 29 tháng 12, 2009
Android: SharedPreferences
SharedPreferences let you save groups of key/value pairs of primitive data as named preferences. SharedPreferences is a lightweight mechanism to store a known set of values such as: user preferences, configuration, application settings...
The data which had created by SharedPreferences can be shared between applicaton components running in the same "Context".
Creating and Saving SharePreferences
//Define SharePreference NameNotes:
private static final String STRING_SHAREREF_NAME_USERREF = "USER REFERENCES";
//SharedPreferences object
private SharedPreferences mShareRefs = null;
//Create and save
protected void savePreferences() {
//get value from ui
boolean bAutoUpdate = mCbxAutoUpdate.isChecked();
int iFrequency = mSpinnerFrequency.getSelectedItemPosition();
int iMinMag = mSpinnerMinMagtitude.getSelectedItemPosition();
//Create SharedPreferences object
mShareRefs = getSharedPreferences(STRING_SHAREREF_NAME_USERREF,
Activity.MODE_PRIVATE);
//update to Preference by editor interface.
Editor editor = mShareRefs.edit();
editor.putBoolean(STRING_SHAREREF_USERREF_AUTOUPDATE, bAutoUpdate);
editor.putInt(STRING_SHAREREF_USERREF_FREQUENCYUPDATE, iFrequency);
editor.putInt(STRING_SHAREREF_USERREF_MINMAG, iMinMag);
editor.commit();
}
- If you want to save information that doesn't need to be shared with others component, you can call Activity.getPreferences(Mode) without a specifying preference name.
(Activity).getPreferences(Activity.MODE_PRIVATE);
Retrieve the saved values:
SharedPreferences object offers some method to get persist data (type boolean, String, int, Long, ..):
- getBoolean(..);
- getInt(..);
- getString(..);
- ...
Ref:
- Pro Android June 2009
- Profession Android Application Development.
Android: Services
Android offers several techniques for application to communicate with users with an Activity providing a direct UserInterface, for ex: Notifications, Toast.
- Toasts are a transient, non-modal Dialog-box mechanism used to display information to users without stealing focus from the active application.
- Notifications represent a more robust mechanism for alerting users. Many users, when they're not actively using their mobile phones, they sit silent and unwatched in pocket or on a desk until it rings, vibrates or flashes. Should a user miss these alerts. This case, status bar icons are used to indicate that an event has occurred. All of these attention-grabbing antics are available within Android as Notifications.
- Alarms provide a mechanism for fi ring Intents at set times, outside the control of your application lifecycle. An Alarm will fire even after its owner application has been closed, and can (if required) wake a device from sleep.
Creating and Controlling Service
Services is extended from Service base class. Services are designed to run in the background, so they need to be started, stopped and controlled by other application component.
Notes:
- Once you've contructed a new Service, you have to register it in the application manifest file within the service tag:
...
(... to be continuous...)
Ref:
- Pro Android June 2009
- Profession Android Application Development.
Thứ Hai, 28 tháng 12, 2009
Android: Http Connection
Although Android included web-browser application in the basic applications, but there are several benefits to creating thick and thin native application rather than relying on entirely web-base:
- Bandwidth
- Caching
- Native features.
With currently connection methods:
- GPRS, EDGE, 3G.
- Wi-Fi.
more details could collected from reference books below.
Connection permission for Android application
By Eclipse ADT plug-in:
- Open AndroidManifest.xml file (in design mode)
- Select "Permissions" tab ==> click "Add" and select "Uses permission"
- At the "Name" property, select "android.permission.INTERNET"
- Save setting.
By XML editor:
- Open AndroidManifest.xml file (in editor mode)
- Add below code:
Open an URL connection and get content:
public static String getHttpContent(String prURL) {
String strResult = "";
StringBuffer sbfResult = new StringBuffer();
String newline = System.getProperty("line.seperator");
try {
URL url = new URL(prURL);
URLConnection urlcon = url.openConnection();
HttpURLConnection httpurlcon = (HttpURLConnection) urlcon;
int responseCode = httpurlcon.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream in = httpurlcon.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line = "";
while ((line = br.readLine()) != null) {
sbfResult.append(line).append(newline);
}
br.close();
in.close();
}
} catch (Exception e) {
sbfResult.append(e.getMessage()).append(newline);
}finally{
if (sbfResult != null) {
strResult = sbfResult.toString();
}else{
strResult = "StringBuffer has failed.";
}
}
return strResult;
}
}
Referenced:
- Pro Android June 2009
- Profession Android Application Development.
Thứ Năm, 24 tháng 12, 2009
Android: Overridable functions in Application's lifecycle
onSaveInstanceState() is called by Android if the Activity is being stopped and may be killed before it is resumed! This means it should store any state necessary to re-initialize to the same condition when the Activity is restarted. It is the counterpart to the onCreate() method, and in fact the savedInstanceState Bundle passed in to onCreate() is the same Bundle that you construct as outState in the onSaveInstanceState() method.
Thứ Tư, 23 tháng 12, 2009
Android: Introduction
- §Built on Linux kernel.
- §For open handset devices.
- §Open-source libraries for Web, SQLLite, OpenGL, SSL,…
- §Base on C/C++ Linux kernel.
- §Fully support for Java developer (by JNI).
- §Use XML for flexible UI and Effect definition.
- §Have a lot of applications fully support for PIM. (Contacts, Calendar, Phone, SMS Manager, Browser, Player, ..)
Android Application Software Stack

The Dalvik Virtual Machine
The Dalvik VM is a registered-base virtual machine. It is optimized for low memory requirements, and is designed to allow for multiple VM instances to run at once, relying on underlying operating system for process isolating, memory management and threading support. Dalvik use .dex files format:
A dx tool will compile Java class files to. dex file format. Multi classes are included in one .dex file, alls duplicate string or resource will be reduced for smallest size. Java byte codes are also converted into a alternative instruction set used by Dalvik VM. Dalvik executables may be modified again when they get installed onto a device.
Dalvik VM was slimmed down to use less space. Dalvik has modified constant pool to use only 32-bit indexes to simplify the interpreter. Dalvik VM use it own byte code, not Java byte code. The name “Dalvik” is belong to the name of a village in Iceland where Dan Bornstein’s ancestors lived. -The executable code on Android, as a result in Dalvik VM, is based not on Java byte code, but on .dex files format instead. -The java compiled class or .jar standard executable file are not compatible with Android. Why no “JIT” : Google has fine-tuned the garbage collection in the Dalvik VM, but it has chosen to omit a just-in-time (JIT) compiler, in this release at least. The company can justify this choice because many of Android’s core libraries, including the graphics libraries, are implemented in C and C++. For example, the Java graphics APIs are actually thin wrapper classes around the native code using the Java Native Interface (JNI). Similarly, Android provides an optimized C-based native library to access the SQLite database, but this library is encapsulated in a higher-level Java API. Because most of the core code is in C and C++, Google reasoned that the impact of JIT compilation would not be significant.
Thứ Năm, 17 tháng 12, 2009
Android: Error on missing resource
Thứ Năm, 10 tháng 12, 2009
How to create a certificate with "makekeys"
Create a self-sign certificate to sign on MIDlet, Symbian apps, Applet, .Net appls, ..
Resource:
Command:
%prompt%>makekeys -expdays 3650 -cert -password yourpassword -len 2048 -dname "CN=CertificateName OU=OrganizationUnit OR=ORganization CO=COuntry EM=yourEMail@now
here.com" keyfilename.key certificatefilename.cer
Result:
Good luck!!
Thứ Ba, 8 tháng 12, 2009
Symbian - Carbide: Compilation Fails: Bareword Found Where Operator Expected (Wrong Active Perl version)
Compilation Fails: Bareword Found Where Operator Expected
Problem: When compiling an application, the process fails. The Problems view of Carbide.c++ reports that a .hlp.hrh file cannot be opened. In the Console view, problems with a Perl script are obvious (params.pm).
Cause: The version of Perl on your system is newer than 5.6.x. The Symbian OS toolchain is not fully compatible to the 5.8.x/5.10.x release – you will probably not notice it for most projects, but, for example, compiling help files does not work with ActivePerl 5.8/5.10.
Solution: Either install Perl 5.6.1 , or follow the steps at http://wiki.forum.nokia.com/index.php/KIS001302_-_Compiling_context-sensitive_help_fails_with_latest_version_of_Perl:
Go to your SDK installation's "Epoc32\tools\perllib" path:
- Open file args.pm, change the following line (# 688)
$self->_iSpecArray->{$aName}= New CArgsSpec($aName, $aDefault, $aPattern,
$aExclusions, $aMandatory, $aRepeatable);
to
$self->_iSpecArray->{$aName}= CArgsSpec->New($aName, $aDefault, $aPattern,
$aExclusions, $aMandatory, $aRepeatable);
- Open file params.pm, search for the word "New" and replace it with "foo->New()"; for example, if there is a function "New CLogs()".
Reference from Developer.Symbian.com and Wiki.forum.nokia.com
Thứ Hai, 9 tháng 11, 2009
Thứ Tư, 21 tháng 10, 2009
Thứ Ba, 7 tháng 7, 2009
Bonus Games: Free Popcap games
Bước 1: Bật thuộc tính show hidden files and folders của window explorer.
Bước 2: Lên Popcap site download về một game nào đó (giờ đang có game Plants vs Jombies rất hài)
Bước 3: Cài đặt game này vào máy (chỉ có next next và next), ví dụ cài vào C:\games\PnJ\ và tập tin chạy game sau khi cài đặt là "PnJ.exe". Mở sẵn một cửa sổ Window Explorer ở vị trí thư mục cài đặt game.
Bước 4: Chạy PnJ.exe để chơi game. Popcapgame chưa đăng ký sẽ hiển thị một màn hình lựa chọn đăng ký (Buy) hoặc chơi thử (Play trial). Chọn Play Trial, khi vào đến màn hình chính của game thì ... qua bước 5 nha.
Bước 5: Switch ra ngoài window explorer. Bây giờ trong cửa sổ Window Explorer đã mở lúc nãy sẽ thấy có 1 file thực thi ẩn có tên "popcapgame1.exe" (hoặc một file thực thi ẩn có dung lượng tương đối bằng (nhỏ hơn) dung lượng file thực thi game PnJ.exe)
Bước 6: Đổi thuộc tính của file popcapgame1.exe thành Read-Only và bỏ thuộc tính Hidden. Ok
Bước 7: Tắt chương trình game đang chạy (tắt luôn cửa sổ Trial Game của Popcap). Quay lại cửa sổ Window Explorer, xóa file PnJ.exe và đổi tên popcapgame1.exe thành PnJ.exe.
Bước 8: Thực thi game PnJ.exe và ... hưởng thụ cuộc chơi miễn phí he he he..
Làm thử vài chục game từ cổ chí kim bắn trứng, hứng kim cương, dương quả tiễn rocket, lẫn các
game mới hấp dẫn như heavy weapon, plants vs jombies, peg night đều okie ^_^. Thôi chơi game tiếp thôi, chơi hoài cháy máy quá. ^_^
Thứ Sáu, 12 tháng 6, 2009
Bonus Manga: Manga terms
Phân loại theo khán giả:
Kodomo: dành cho trẻ em
Joise hoặc redikomi: dành cho phụ nữ
Shoujo: dành cho con gái
Shounen: dành cho con trai
Shounen-ai: quan hệ giữa nam-nam cấp độ 1
Shoujo-ai : quan hệ giữa nữ-nữ cấp độ 1
Yaoi : quan hệ giữa nam-nam cấp độ cao hơn (nghĩa là trong đó sẽ có nhiều *** hơn)
Yuri : quan hệ giữa nữ-nữ cấp độ cao hơn ( tương tự yaoi )
Hentai : được chuyên thể từ game ***
Ecchi : những manga này có lẽ hơn " hở " 1 chút nhưng thua Hentai
Chú thích : *** là những cái "không ai nói ra mà ai cũng biết"
Các thuật ngữ khác:
Mangaka :danh từ chỉ các tác giả manga
Doujinshi: là thể loại ăn theo của manga , dựa vào manga phần nào hoặc hoàn toàn khác manga
Doujinshika:danh từ chỉ các tác giả Doujinshi
Fanfiction :gần gần giống Doujinshi , chỉ có điều là ko phải vẽ mà là viết văn.
ADR (Automated Dialogue Recording) :là cách tạo soundtrack tiếng Anh phù hợp với cử động miệng trên màn hình.
AMV (Anime Music Video) :là các video clip sử dụng cảnh trong anime và *****g music vào .Các otaku thường rất khoái cai này.
Anime TV Series :là Anime dài tập được chiếu trên TV .Nội dung thường khác manga 1 chút & điều đó chính là yếu tố ko gây hứng thú cho các độc giả sau khi đã xem Manga .Sau khi chiếu hết trên TV, các Anime này mới được sản xuất ra DVD/VCD/VHS bán cho các otaku.
Anime OVA/OAV :chỉ khác TV Series là nó được chuyển thẳng ra DVD/VCD/VHS để bán chứ không chiếu trên truyền hình. Số lượng các bản OAV thường rất ít ,các otaku dĩ nhiên rất hứng thú sưu tập nó.OVA luôn được làm kĩ hơn Anime Series (về đồ họa).Nội dung thường là tiếp theo hay là các câu chuyện ngoài lề Anime Series.
Anime the Movie :cũng gần giống với OAV ,nhưng ko chia làm nhiều chap mà là 1 câu chuyện liền mạch với thời lượng rất ngắn và được chiếu trong các rạp (màn ảnh rộng) .Đây cũng là thể loại Anime có cơ hội đoạt Oscar và các giải khác . Anime đầu tiên dành giải thưởng đó là Sen to Chihiro Kamikakushi (Spirited Away) của đạo diễn lừng danh Hayao Miyazaki, đoạt Oscar cho phim hoạt hình hay nhất năm 2001.
Art Work :giống giống Fanart , nhưng chất lượng hơn vì do các họa sĩ chuyên nghiệp vẽ. (cũng có artbook của loại này)
BGM (Background Music) là nhạc nền. (nhạc không lời và cả có lời).
CGI/CG (Computer Generated Imagery): là công việc thiết kế hình ảnh trên máy tính.
CG Division: là hệ thống máy tính và thiết bị hỗ trợ CGI
Chibi :C&B , dùng để chỉ các nhân vật được vẽ dưới hình dáng nhỏ nhắn , dễ xương ( đầu bự ,thân nhỏ )
Cosplay (Costume Play) : diễn kịch , hoặc là hóa trang( mặc đồ ,làm tóc)thành các char trong Anime & Manga.*vui thật*
Digisub (Digital Subtitle) :là một fansub nhưng ở dạng kỹ thuật số cho máy tính.
Dub là *****g tiếng trong phim. (Eng Dub, Fren Dub, Chin Dub,...)
ED (ending theme)& OP( opening theme) :music clip mở đầu và kết thúc của Anime ( hay 1 chap Anime)
Episode (Ep hay Epi):giống như chapter trong Manga.Mỗi Epi thường dài khoảng 20-25 min.
Eye Catch :là chỉ những đoạn ngắt giữa Anime. Thường thì Eye Catch có độ dài chỉ dưới 10 giây với vài hình ảnh có kèm theo tên của Anime.
Fan Art :tranh do fan vẽ
Fansub:là sub do fan làm.
Fanboy Một tên chỉ sống vì anime. Ngoài ra, thành một fanboy có nghĩa là lập một "thánh đường" hay tôn thờ bất cứ một nhân vật nữ của Anime nào và thậm chí là làm cái đuôi của những "tiểu thư" cosplay theo nhân vật đó.
Fandom: nhóm người có chung sở thích (như chúng ta chẳng hạn)
Fangirl: ngược lại với Fanboy
Henshin có nghĩa là biến đổi ,hóa thân ,biến hình (trong A-M)
Idol :thần tượng.
Lemon :là Fiction có nội dung về quan hệ thể xác. Từ này ít dùng hơn nhiều so với Hentai hay Doujinshii.
Omake :là đoạn phim thêm quay những cuộc phỏng vấn hoặc hài kịch ngắn. Nói chung nhiều Anime/Manga có các đoạn omake.
Original DVD :là DVD gốc, được sản xuất bởi chính hãng.. DVD gốc có rất nhiều interesting stuffs cho người xem như Cover và Box cực đẹp,Trailer, Char's Profile, Other Film's Trailer, Making of the Film, Gallery,... Được sở hữu những thứ này là mơ ước của Otaku (1 rich otaku cơ ,vì những thứ này rất mắc)
OST (Original Sound Track) :được dùng để chỉ chung các đoạn nhạc nền trong phim, kể cả OP và ED.
RPG = Role Playing Game: người ta dịch từ này là Game Nhập Vai. Có một số Anime có cốt truyện dựa theo các RPGs và cả Online RPGs.
RAW: file Anime gốc ,chất lựơng 5 sao.
Seiyuu :diễn viên *****g tiếng. Thường các Seiyuu đều là ca sĩ hay diễn viên cả.
Side Story : là truyện ngoài lề.Nội dung là khai thác các khía cạnh khác trong Anime-Manga gốc ,hoặc nói rõ hơn về 1 nhân vật nào đó trong Anime-Manga gốc.
Subtitle (Sub) :là phụ đề (dòng chữ hiện phía dưới cho biết nhân vật trong phim đang nói gì).
Trailer: là đoạn phim quảng cáo ngắn về 1 Anime.
Shoujo Manga :Manga dành cho con gái, được biệt là dành cho thiếu niên. Về một phía nào đó, nó giống với "tiểu thuyết tím". Thế nhưng nó không hẳn là như vậy.vì trong Shojo Manga tràn đầy những hình vẽ hoa lệ và lời văn hoa mỹ. Shojo Manga có thể dễ dàng được nhận ra với những cậu "đẹp trai", cô gái mắt to, hoa thơm rơi đầy trang... (Shojo có nghĩa là **** gái")
Josei Manga :Cũng là một dạng như Shojo Manga nhưng được vẽ dành cho lứa tuổi lớn hơn ( các bà vợ, nữ nhân viên ...). Thể loại này cũng cuốn hút nữ thiếu niên và đôi khi ... cả con trai. Chúng ta cũng có thể loại Seinen Manga dành cho con trai đã trưởng thành.
Shonen Manga :Manga nhắm vào các cậu con trai, đánh nhau chí ***e, đầy bạo lực, đẫm máu, kèm theo một mớ "anh hùng" ("Tôi chiến đấu cho trái đất... blah...blah...blah...)...và thường có cả những cô gái ngực to nữa. Shounen nghĩa là **** trai".
Shounen Ai :Hãy cẩn thận phân biệt giữa Shounen và Shounen Ai, chúng không hề giống nhau. Shounen Ai nhắm vào con gái. Các cô gái "phát cuồng" lên vì cái nhánh này của Shojo Manga. Đầu tiên, đây chỉ là một bộ phận nhỏ của Shojo Manga, sau đã phát triển thành một thể loại riêng biệt. Shounen Ai mở ra trước mắt người đọc thế giới của những anh chàng đẹp trai và đồng tính luyến ái. Về một phía cạnh nào đó, những anh chàng này đẹp trai, hào hoa và mối tình giữa bọn họ lãng mạn tới mức nó hẫp dẫn các cô gái trẻ một cách kì lạ. Ngày nay, thể loại này được biết đến một cách rộng rãi trong giới đọc Shojo Manga. Một số trong thể loại này cho ta thấy một thể giới không có gì khác ngoài các chàng trai "xinh đẹp". (Trong tiếng Nhật, "ai" nghĩa là "yêu" như từ "ái" của Trung Quốc vậy. Ta có thể hiểu Shounen Ai là "tình yêu con trai")
Yaoi :Một thứ không thể tưởng tượng được do phụ nữ sáng tác. Thể loại này tập trung vào tình yêu và các cảnh làm tình CON TRAI với CON TRAI. Nó có thể kết thúc với các cảnh kinh khủng với các hành động làm thực ... !!!
Ecchi / Hentai :Ecchi Manga là tiếng lóng của Hentai Manga. Hentai tiếng Nhật nghĩa gốc là "dị thường", nhưng ở phương Tây, nó được dùng với nghĩa là "mất dạy" hay "***". Không chỉ thể hiện các cảnh làm tình giữa nam và nữ mà còn thể hiện CON TRAI với CON TRAI, CON GÁI với CON GÁI.
Otaku : người hâm mộ cuồng nhiệt Anime hay Manga
Shoujo Ai : nghe là hỉu liền đúng ko . Dây là dạng manga mà tình cảm của các đôi trong này là GIRL x GIRL . Nhưng mức độ nhẹ nhàng thui , chỉ là yêu , thích chứ ko quá đáng
Yuri : Đây là thể loại manga mà mối quan hệ đó là những quan hệ của GIRL x GIRL nhưng là những quan hệ thật sự như girl x boy bình thường
(sưu tầm internet)
Thứ Hai, 8 tháng 6, 2009
Bonus: Hướng Dẫn Sử Dụng DNS Free
| Hướng Dẫn Sử Dụng DNS Free |
| Domain quốc tế (.com /.net / .org / .info ....) của bạn sẽ không thể chạy nếu nó chỉ là một domain mà không có Hosting. Để cho Domain hiểu được Hosting thì phải thông qua DNS. Hay nói cách đơn giản, DNS tức là cầu nối để Domain và Hosting hiểu nhau, cùng nhau song song tồn tại trên Internet. | |
| |
(Nguồn: suutam) |
Thứ Ba, 26 tháng 5, 2009
Web PHP - Symfony: Symfony Vietnam tutorial page
Nội dung: Thực hành Symfony trong 24 ngày
Link chính: http://www.symfony-project.org/
Link download: http://www.symfony-project.org/installation
Các link học theo ngày:
Ngày 1: Bắt đầu dự án
Ngày 2: Mô tả dự án
Ngày 3: Data Model
Ngày 4: Controller và View
Ngày 5: Routing
Thứ Bảy, 25 tháng 4, 2009
Java: Spring beginning (Review Project Part 2)
Spring là một java framework nguồn mở dùng ở tầng "bussiness layer" trong kiến trúc sau:
Với IDE MyEclipse:
- Hãy tạo một project trống rỗng với tên DemoSpring
- Ở cửa sổ Package Explorer, right click vào "DemoString" -> MyEclipse -> Add Spring Capabilities, chọn Finish ở cửa sổ "Add Spring Capabilities"
Sau khi Finish, kết quả ở cửa sổ Package Explorer sẽ có thêm file applicationContext.xml (file này là file định nghĩa các bean) và Spring 2.5 reference library:
- Tới đây, ta tạm ngưng các hoạt động với Spring để định nghĩa các đối tượng, hành động ví dụ. Tạo các lớp như sau :
và codes:------- DemoSpring.java --------------
import java.util.Scanner;------- IActionClass.java --------------
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
/**
* @author Hung.Trinh
*/
public class DemoSpring {
private static String CONFIG_FILE_LOCATION = "applicationContext.xml";
private static volatile BeanFactory beanFactory = null;
/**
* Copyright by tqhung at Apr 24, 2009 - 3:09:09 PM
* @param args
*/
public static void main(String[] args) {
System.out.println("Hello to Demo Using Spring with MyEclipse.");
Scanner sn = new Scanner(System.in);
String beanname = "";
getBeanFactory();
do {
try {
beanname = sn.next();
if (beanname.compareToIgnoreCase("exit") == 0) {
break;
}
IActionClass aclass = (IActionClass) beanFactory.getBean(beanname);
System.out.println(aclass.showMessage());
} catch (BeansException be) {
System.out.println("No bean found.");
} catch (Exception e) {
System.out.println(e.getMessage());
}
} while (true);
System.out.println("completed");
}
public static BeanFactory getBeanFactory() {
if (beanFactory == null) {
final ClassPathResource resource = new ClassPathResource(CONFIG_FILE_LOCATION);
beanFactory = new XmlBeanFactory(resource);
}
return beanFactory;
}
}
/**------- ActionClass1.java --------------
* @author Hung.Trinh
*/
public interface IActionClass {
String showMessage();
}
/**------- ActionClass2.java --------------
* @author Hung.Trinh
*/
public class ActionClass1 implements IActionClass{
public String showMessage(){
return "In action 1 of class" + ActionClass1.class.toString();
}
}
/**- Công đoạn kế tiếp là ta định nghĩa các bean cho Spring. Mở file applicationContext.xml:
* @author Hung.Trinh
*/
public class ActionClass2 implements IActionClass{
public String showMessage(){
return "In action 2 of class" + ActionClass2.class.toString();
}
}
-------- applicationContext.xml - Default ----------
[?xml version="1.0" encoding="UTF-8"?]Có 2 cách định nghĩa bean: định nghĩa bằng dòng lệnh và định nghĩa bằng giao diện. Định nghĩa bằng dòng lệnh theo cấu sẽ đơn giản hơn với người lập trình chuyên sâu. Ở đây coi như ta chưa biết gì, ta dùng giao diện vậy :D. Mở cửa sổ Spring Explorer (Window -> Show View -> Other.. -> Spring Explorer), right click lên "bean" chọn "New Bean"
[beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"]
[/beans]
Và định nghĩa "action1", "action2" tương ứng với 2 lớp ActionClass1 và ActionClass2 mới vừa được tạo:Nên nhớ là sau mỗi lần tạo bean bạn đều phải thực hiện save file applicationContext.xml. Kết quả sau 2 lần tạo bean, nội dung file applicationContext.xml sẽ là:
--------- applicationContext.xml - Configured ----------
[?xml version="1.0" encoding="UTF-8"?]nhưng thực tế cần thì ít hơn:
[ơbeans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"]
[bean name="action1" class="ActionClass1" abstract="false"
lazy-init="default" autowire="default" dependency-check="default"]
[/bean]
[bean name="action2" class="ActionClass2" abstract="false"
lazy-init="default" autowire="default" dependency-check="default"]
[/bean]
[/beans]
[?xml version="1.0" encoding="UTF-8"?]save lại 1 lần nữa cho chắc ăn :D,
[beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"]
[bean name="action1" class="ActionClass1" /]
[bean name="action2" class="ActionClass2" /]
[/beans]
Tới đây bạn có thể test kết quả vừa làm. Run DemoSpring java application, ở console, nhập chuỗi "action1" -> enter, "action2" -> enter sẽ thấy kết quả:
input : action1 --> output: In action 1 of classclass ActionClass1
input : action2 --> output: In action 2 of classclass ActionClass2
input : exit --> output: completed
Chúc thành công.
Thứ Tư, 1 tháng 4, 2009
Java : Mapping DB tour with Middlegen and Hibernate (Review Project Part 1)
Để bắt đầu, tui chọn sử dụng MyEclipse để đỡ mắc công cài các plugin lằng nhằng cho mấy cái framework khủng, trong khi thứ tui iu thích nhẹ nhàng lại là Eclipse đã từng cắn xé Javacard.
Quả thật là sau khi cài đặt MyEclipse vào, tui nhận thấy hầu như các framework mình cần cho thực tế đều có sẵn (thiệt đỡ quá). Đối với dự án tui tìm hỉu chỉ cần thêm một cái MySQL connector và vài cục jar log4net, .. là xong, he he
Khởi động ME (MyEclipse), theo thói quen tui tạo luôn một project rỗng trơn không gì cả, xài lại một cái ant builder.xml có sẵn đâu đó và sửa lại mỗi properties name.
Bắt đầu với Hibernate và Middelgen:
- Đọc lòng vòng thì tui biết, Hibernate chỉ đơn thuần là để "mapping" với một database ở đâu đó. Lợi ích của dùng Hibernate là để đơn giản hóa và chuẩn hóa thao tác với cơ sở dữ liệu, biết nhiêu đó là đủ rùi.
- Tuy nhiên, để có thể hoàn thành việc "mapping" này thì cần phải có các thứ linh tinh khác như sau:
+ hibernate mapping files: các file cấu hình định nghĩa các bảng trong database. Thường mỗi bảng ta lại định nghĩa một file dạng "
+ hibernate configuration file: một file cấu hình để định vị đối tượng database bao gồm : connection string, database connection provider, username, password ...
+ Implementation files: các file hoặc gọi là các lớp thể hiện của các bảng trong database.
Chài ai, tìm hiểu đến đây, tui nghĩ hỏng lẽ mình thay cái thao tác Connection rồi query xưa cũ lòng thòng bằng một đống file ngồi gõ chít bỏ. Tính sơ sơ ra mỗi table có thao thác là phải tạo ra 1 file mapping và 1 file đối tượng, Hibernate thiệt là khùng hết sức !! T_T !! Nhưng việc làm thủ công đó là trước đây, các anh các chị trước đây đã chịu khổ và sản sinh ra công cụ Middlegen...
- Middlegen được ứng dụng để truy vấn đến database và xuất ra các table mapping file
một cách tự động và chuẩn xác. Đồng thời Middlegen cũng tự động phát sinh java code các lớp đối tượng table tương ứng, nhưng tui được khuyến cáo là không nên dùng những lớp code này. Tìm hiểu tới đây là đủ nhức mắt ngứa tay rồi, thôi quay lại cái bàn phím thôi.
- Để sử dụng Middlegen, ta tạo một middlegen build file (xml) bằng cách right click vào Project -> New -> Other -> Middlegen -> Middlegen Build File. Click next đến của sổ "Configure Database and Table", ở đây phải cung cấp các thông số bắt buộc để xác định database như: xác đinh gói JDBC, Database URI, Username, Password như hình dưới:
sau đó click "Finish" cửa sổ Middlegen Generator sẽ mở thể hiện mối quan hệ các bảng trong cơ sở dữ liệu, click "Generate" và sau đó đóng cửa sổ. Kiểm tra lại thư mục "src" của project sẽ thấy package các file Middlegen vừa xuất
tới đây tui được các đàn anh mách bảo là xóa hết các class object đi, chỉ để lại các mapping file và right click -> Hibernate Synchronizer -> Synchronize Files, kết quả là được 4 package như sau:
tạm thời tui chỉ hiểu 4 package này chứa các lớp đối tượng thể hiện chính xác các bảng dữ liệu và mối quan hệ bảng ở database. Tới đây, dường như nhiệm vụ của Hibernate và Middlegen đã hoàn thành.Sau đó còn sử dụng tiếp String, Mina 2.0, ... hồi sau sẽ rõ !!!














