2013年5月8日 星期三

Activity切換及返回時的動畫

如果再每個頁面都去定義intent時要用哪種動畫真的很麻煩,還不如直接定義在application中,這要整個App都有動畫囉~

詳細的解說可以到這個頁面
http://stackoverflow.com/questions/2625812/start-activity-with-an-animation

2013年3月21日 星期四

Intent.putExtra一個Class

有一個class,裡面都是get與set方法,我想把他putExtra到另外一個Activity.
方法就是在那個class 後面加上implements Serializable就可以使用putExtra這個class了

例如:public class Car implements Serializable {...}



2013年3月12日 星期二

解決Activity has leaked window … that was originally addedㄐ

今天Note Tab 10.1上一直出現以下錯誤


05-05 10:36:41.009: E/WindowManager(4243): Activity com.tao.MyActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405241b0 that was originally added here
05-05 10:36:41.009: E/WindowManager(4243): android.view.WindowLeaked: Activity com.tao.MyActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405241b0 that was originally added here
05-05 10:36:41.009: E/WindowManager(4243):     at android.view.ViewRoot.(ViewRoot.java:265)
05-05 10:36:41.009: E/WindowManager(4243):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
05-05 10:36:41.009: E/WindowManager(4243):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
05-05 10:36:41.009: E/WindowManager(4243):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
05-05 10:36:41.009: E/WindowManager(4243):     at android.app.Dialog.show(Dialog.java:241)
05-05 10:36:41.009: E/WindowManager(4243):     at android.app.ProgressDialog.show(ProgressDialog.java:107)
05-05 10:36:41.009: E/WindowManager(4243):     at android.app.ProgressDialog.show(ProgressDialog.java:95)
05-05 10:36:41.009: E/WindowManager(4243):     at com.unifable.activity.MySecretaryActivity.onCreate(MySecretaryActivity.java:50)
05-05 10:36:41.009: E/WindowManager(4243):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-05 10:36:41.009: E/WindowManager(4243):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
05-05 10:36:41.009: E/WindowManager(4243):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-05 10:36:41.009: E/WindowManager(4243):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-05 10:36:41.009: E/WindowManager(4243):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-05 10:36:41.009: E/WindowManager(4243):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 10:36:41.009: E/WindowManager(4243):     at android.os.Looper.loop(Looper.java:130)
05-05 10:36:41.009: E/WindowManager(4243):     at android.app.ActivityThread.main(ActivityThread.java:3683)
05-05 10:36:41.009: E/WindowManager(4243):     at java.lang.reflect.Method.invokeNative(Native Method)
05-05 10:36:41.009: E/WindowManager(4243):     at java.lang.reflect.Method.invoke(Method.java:507)
05-05 10:36:41.009: E/WindowManager(4243):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:906)
05-05 10:36:41.009: E/WindowManager(4243):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:664)
05-05 10:36:41.009: E/WindowManager(4243):     at dalvik.system.NativeStart.main(Native Method)




這是在做一個項目的時候遇到的問題:在第一界面的Activity中,為了避免程序假死帶來的糟糕的用戶體驗,採用非同步任務AsyncTask來訪問網絡,與服務器進行交互,並用
ProgressDialog控件來告知用戶當前的程序進度。

在網上查了下別人的資料。才終於明白了原因。
上面的異常的意思是:存在窗口句柄的洩漏,即未能及時的銷毀某個PhoneWindow.

為什麼會出現這樣的情況,因為,在非同步任務裡面已經發生了嚴重的錯誤,而導致Activity的強制關閉。Activity強制關閉了,可是ProgressDialog並沒有dismiss()掉,所以出現了
窗口句柄的洩漏。 而且,更嚴重的是,這個異常會覆蓋我們在AsyncTask裡面發生的真正異常,這往往會誤導我們,把過多的精力放在查找所謂的內存洩漏的上面,而不是查找AsyncTask
中出現的錯誤。

參照別人的解決方法:
本解決方法並不能真正的解決問題,但是在一定程度上可以將真正導致錯誤的異常信息顯露出來。即重寫Activity的onDestory()方法,在該方法中調用dismiss()來解除對ProgressDialog
的引用。

再加上當離開Activity後離開AsyncTask執行
if(!AsyncTask.isCancelled()){
AsyncTask.cancel(true);
}

我的應用程式是在onCreate時都會使用
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);   //保持螢幕橫式
來保持螢幕橫式,但我發現在3.2版本的設備上或某些設備都還是會先轉直式再轉橫式,造成2次onCreate,所以我改成直接在AndroidManifest.xml的每個Activity加上android:screenOrientation="landscape"後似乎就不會有這個問題了

2013年3月6日 星期三

ubuntu下使用 eclipse 開發 android 時抓不到htc手機

今天接上HTC Incredible S開發時裝置抓不到,照了這位大大的文章後還是抓不到(http://wangjenmin.blogspot.tw/2011/07/ubuntu-eclipse-android-htc.html)

使用sudo ./adb devices使令察看顯示no permissions,後來照了這篇文章後解決了(http://stackoverflow.com/questions/9210152/set-up-device-for-development-no-permissions)

主要是sudo chown root. /etc/udev/rules.d/51-android.rules這一句,分享給同行們

2013年1月29日 星期二

從Uri取得圖片路徑

有時候想要從URI知道此圖檔的目錄,例如在使用Receiving Content的時候如果想從URI取得此圖檔的目錄可以使用此方法

           try {  
                Uri selectedImage = data.getData();  
                String[] filePathColumn = { MediaStore.Images.Media.DATA };  
  
                Cursor cursor = getContentResolver().query(selectedImage,  
                        filePathColumn, null, null, null);  
                cursor.moveToFirst();  
  
                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);  
                String picturePath = cursor.getString(columnIndex);  
                cursor.close();  
                imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));  
            } catch (Exception e) {  
                // TODO: handle exception  
                e.printStackTrace();  
            }  


轉自http://blog.csdn.net/shaojie519/article/details/7626962

星期、月份英文縮寫

中文 英文 3字母 縮寫 3字母 縮寫 2字母 縮寫 2字母 縮寫 1字母 縮寫 1字母 縮寫 其他 縮寫 星期日 Sunday SUN Sun SU Su S S 星期一 Monday MON Mon MO Mo M M 星期二 Tuesday TUE Tue TU ...