1.定时清理类似C:\Documents and Settings\Android123\.android下的.android文件夹
2.可以通过settings----Language&software key进行是否在输入时显示软键盘的设置
3.当进行代码输出调试的时候,有下面几种输出方式:
/* 打印出不同的log信息 */
Java代码
1 01.Log.v(TAG, "VERBOSE");
2
3 02.Log.d(TAG, "DEBUG");
4
5 03.Log.i(TAG, "INFO");
6
7 04.Log.w(TAG, "WARN");
8
9 05.Log.e(TAG, "ERROR");
10 复制代码
4.Drawable 文件夹相关1 资源文件名字命名需要全部为小写形式,并且不能是单独的数字命名
在之前的版本中,只有一个drawable,而2.1版本中有drawable-mdpi、drawable-ldpi、drawable-hdpi三个,这三个主要是为了支持多分辨率。
drawable- hdpi、drawable- mdpi、drawable-ldpi的区别:
(1)drawable-hdpi里面存放高分辨率的图片,如WVGA(480x800),FWVGA (480x854)
(2)drawable-mdpi里面存放中等分辨率的图片,如HVGA(320x480)
(3)drawable-ldpi里面存放低分辨率的图片,如QVGA(240x320)
系统会根据机器的分辨率来分别到这几个文件夹里面去找对应的图片。在开发程序时为了兼容不同平台不同屏幕,建议各自文件夹根据需求均存放不同版本图片
5.Context字面意思上下文:
位于frameworkpackage的android.content.Context中,其实该类为LONG型,类似Win32中的Handle句柄,很多方法需要通过Context才能识别调用者的实例,比如说Toast的第一个参数就是Context,一般在Activity中我们直接用this代替,代表调用者的实例为Activity,而到了一个button的onClick(View view)等方法时,我们用this时就会报错,所以我们可能使用ActivityName.this来解决,主要原因是因为实现Context的类主要有Android特有的几个模型,Activity、Service以及BroadcastReceiver。
常规需要Context实例的方法主要有各种Service实现的类,比如说SensorManager在实例化时需要getSystemService(String)方法就必须由Context的实例执行,还有一些私有的文件系统I/O比如说openFileInput以及常用的Toast的makeText方法等
2 6. emulator: ERROR:the user data image is used by another emulator. aborting
出现这种错误我在网上查了下,好像是由于程序没有正常关系导致的,至于更深层次的原因,我也还没搞清楚,如果哪位知道帮告知下
暂时处理方法:
Java代码 01.adb kill-server
1 02.adb devices
2 复制代码
3 7.设置窗口格式为半透明
Java代码
4 01.getWindow().setFormat(PixelFormat.TRANSLUCENT);
5 复制代码
6 8.取得屏幕大小
方法A:
Java代码
01.WindowManagerwindowManager = getWindowManager();
7
02.Displaydisplay = windowManager.getDefaultDisplay();
8
03.hAndW[0] =display.getWidth();
9
04.hAndW[1] =display.getHeight();
10 复制代码
方法B:
Java代码
01.DisplayMetricsdm = new DisplayMetrics();
02.getWindowManager().getDefaultDisplay().getMetrics(dm);
03.hAndW[0] =dm.widthPixels;
04.hAndW[1] =dm.heightPixels;
复制代码
9.取得内存大小
Java代码
01.ActivityManager.MemoryInfooutInfo = new ActivityManager.MemoryInfo();
02.activityManager.getMemoryInfo(outInfo);
03.//可用内存
04.outInfo.availMem
05.//是否在低内存状态
06.outInfo.lowMemory
复制代码
10.监听App安装/卸载事件
A.Define a class derived from class BroadcastReceiver;
B.Register broadcast receiver;
Java代码
01.
02.MyBroadcastReceivermyReceiver = new MyBroadcastReceiver();
03.
04. IntentFilterfilter = new IntentFilter(Intent.ACTION_PACKAGE_INSTALL);
05.filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
06.filter.addAction(Intent.ACTION_PACKAGE_ADDED);
07.filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
08.filter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
09. ...
10.filter.addDataScheme("package"); //This line is very important.Otherwise, broadcast can't be received.
11.registerReceiver(myReceiver, filter);
11.取得IP地址
Java代码
01.
02.A.Connectvia WIFI
03. WifiManagerwifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
04. WifiInfowifiInfo = wifiManager.getConnectionInfo();
05. intipAddress = wifiInfo.getIpAddress();
06.
07. B.Connectvia GPRS
08. publicString getLocalIpAddress(){
09. try{
10.for(Enumeration<NetworkInterface> en =NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();){
11.NetworkInterface intf = en.nextElement();
12. for(Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses();enumIpAddr.hasMoreElements();){
13. InetAddressinetAddress = enumIpAddr.nextElement();
14. if(!inetAddress.isLoopbackAddress()){
15. returninetAddress.getHostAddress().toString();
16. }
17. }
18. }
19. }catch(SocketException ex){
20.Log.e(S.TAG, ex.toString());
21. }
22. returnnull;
23. }
复制代码
12.MonitorMedia Event: mount/unmount..
A.Define a class derived from classBroadcastReceiver;
B.Register broadcast receiver;
Java代码
1 01.MyBroadcastReceiver myReceiver = newMyBroadcastReceiver();
2 02.
3 03. IntentFilter filter = newIntentFilter(Intent.ACTION_MEDIA_MOUNTED);
4 04.filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
5 05.filter.addAction(Intent.ACTION_MEDIA_EJECT);
6 06. ...
7 07.filter.addDataScheme("file"); //This is important. Otherwise,broadcast can't be received
8 08.
9 09. registerReceiver(myReceiver,filter);