- Auto-import - Ctrl-Shift-O
- Auto-format - Ctrl-Shift-F
- Save - Ctrl-Shift-S
- Refresh - F5
- Debug - F11
- Run - Ctrl-F11 (this hotkey changes the AVD orientation if the focus is on the AVD window)
2. On-device debug (for running debugger only)
- Declare your application as "debuggable" in your Android Manifest. In Eclipse, you can do this from the Application tab when viewing the Manifest (on the right side, set Debuggable to true). Otherwise, in the AndroidManifest.xml file, addandroid:debuggable="true" to the <application> element.
- In your phone, select Settings > Applications > Development > USB debugging. When this option is checked, Windows will detect a new device and prompt for driver update.
- If you want to deploy your app to a device, make sure no emulator is automatically selected in the "Run Configuration".
3. Activity.findViewById(int id)
- The id param is an id attribute of view element in xml, not the commonly referred resource id.
- Retrieve a widget from the layout that is set by setContentView(int). If the widget is not defined in the layout xml file, null will be returned.
- Different from View.findViewById(int id) which looks for a child view in the hierarchy.
4. inflate(int resource, ViewGroup root)
- The root argument is optional. Set to null if you want to omit it.
- If root is not given, the inflater does not know what type of layout parameters to create and therefore ignores all the android:layout_ XML attributes. Instead, use inflate(R.layout.gallery_item, parent, false); The last parameter simply tells the inflater to not add the inflated view to the parent right away.
- http://stackoverflow.com/questions/2869749/inflated-imageview-to-put-in-galleryview-isnt-the-right-size
- All view groups include a width and height (layout_width and layout_height), and each view is required to define them.
- fill_parent (renamed match_parent in API Level 8)
6. Dimension measurement units
- http://developer.android.com/guide/topics/resources/more-resources.html#Dimension
- (px, dp, sp, pt, in, mm)
7. For a list of the widgets provided by Android, see the android.widget package.
8. State List (drawable)
- During each state change, the state list is traversed top to bottom and the first item that matches the current state is used—the selection is not based on the "best match," but simply the first item that meets the minimum criteria of the state.
9. XML No grammar constraints detected for this document
- The regular text editor and the Android layout editor should not complain but the XML editor from WTP will sometimes complain because it doesn’t have a DTD or schema to validate and offer code completion against.
- You can get rid of the warning by going into Window > Preferences > XML > XML Files and setting the “Indicate when no grammar is specified” option to “Ignore”. Then do an XML validation (right-click > Validate) and it should take the warning away.
10. If your application cannot get start, see if you already put all Activities to your AndroidManifest. Activities not in the manifest are not visible to the system!!
11. Common Tasks and How to Do Them in Android
11. Common Tasks and How to Do Them in Android
12. Logging
- Generally, use the Log.v() Log.d() Log.i() Log.w() and Log.e() methods.
- The order in terms of verbosity, from least to most is ERROR, WARN, INFO, DEBUG, VERBOSE. Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept.
- Strip off logs using ProGuard:
http://stackoverflow.com/questions/2446248/deactivate-any-calls-to-log-before-publishing-are-there-tools-to-do-this/2466662#2466662
- To check if a device is active, type "adb devices"
- When the first of an application's components needs to be run, Android starts a Linux process for it with a single thread of execution. By default, all components of the application run in that process and thread.
15. Intent and Intent Filter
- The DEFAULT category is required for the Context.startActivity method to resolve your activity when its component name is not explicitly specified.
- Intent filters are not consulted for explicit intents.
16. In android, the method for registering a listener is setXXXListener but not addXXXListener, which actually reflect the truth in android that one cannot attach multiple listeners to a View.
17. PreferenceActivity
- http://www.cnblogs.com/wservices/archive/2010/07/08/1773449.html
- http://blog.joomla.org.tw/android/183-%E8%B3%87%E6%96%99%E5%84%B2%E5%AD%98%E4%B9%8B%E4%B8%80%EF%BC%9AShared-Preference.html
- http://stackoverflow.com/questions/3630457/clearing-preferences-in-sharedpreferences-in-android-not-just-values
18. Handler
- When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.
19. SD Card path
- 隨著 Android 越來越普及, 軟件數量幾何級上升, 試用新軟件已經成為一種樂趣.
但當經過一段時間, 用家不難發覺 SD card 的根目錄會變得十分混亂. 因為不同的開發者都有建立自己的文件夾, 當軟件被刪除後文件夾卻留在 SD card 裡. 原來由 Froyo 開始, 開發文件便有提及外存路徑的正確位置, 只要開發者把軟件的存取路徑置為 getExternalFilesDir() 或 " /Android/data/<package_name>/files/", 軟件被刪除的時候文件夾及裡面的內容會被一同刪除 .
多一個軟件使用正確路徑, 就少一分混亂. 為保持一個良好 SD card 環境, 請各開發者將你下一個更新把軟件使用的文件夾放入正確位置.
注: 該路徑亦會於 Upgrade 軟件時刪除, 如有大量要保留下載資料的軟件可能不適用.
21. LogCat
- To watch the log of an active device continually:
adb logcat - To dump the whole log:
adb logcat -d - To dump the whole log to a file:
adb logcat -d > log.txt - To filter and display a particular log tag:
adb logcat -s MyLogTag
22. Get the system-dependent newline character by this:
26. Notification Icon Size Guide- public static String newline = System.getProperty("line.separator");
23. Good Reference for SQLite Database
24. Spinner + SimpleCursorAdapter
- When using SimpleCursorAdapter, the primary key of the querying table must be named '_id'
- When binding SimpleCursorAdapter to Spinner and calling getSelectedItem() from Spinner, the item returned by this method is the Cursor that pointing to the selected row.
see also onItemSelected()
25. Toast message can be customized using:
- http://developer.android.com/guide/topics/ui/notifiers/toasts.html
- toast.setView(layout);
27. SQLite default row ID
- You can access the ROWID of an SQLite table using one the special column names ROWID, _ROWID_, or OID.
28. Support Video Format
No comments:
Post a Comment