2014年9月24日 星期三

Application的生命週期

以前一直好奇,Activity有onStart,onResume,onPause,onStop之類的,但extand Application怎麼沒有,原來可以實作ActivityLifecycleCallbacks

原本是想查activity的目前是不是在背景狀態偶然看到的
http://stackoverflow.com/questions/3667022/checking-if-an-android-application-is-running-in-the-background/5862048#5862048

2014年7月2日 星期三

偵測service是否正在執行

private boolean isMyServiceRunning(Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

2014年5月14日 星期三

RadioGroup裡的radiobutton setcheck時沒有反應

重新刷新radioGroup時除了

deviceRadioGroup.removeAllViews();
還要
deviceRadioGroup.clearCheck();

看到網頁後才了解,困擾了好幾天
http://stackoverflow.com/questions/4035465/android-radiobutton-not-able-to-set-using-setcheckedfalse-method

2014年5月10日 星期六

Sqlite在多執行緒

可參考
http://stackoverflow.com/questions/5786206/to-to-implement-a-sqlite-manager-for-thread-safe-read-write-access

2014年5月8日 星期四

Fragment與Activity溝通

在官方的範例中有以下做法
http://developer.android.com/training/basics/fragments/communicating.html

//左側Fragment
public class MainLeftFragment extends Fragment {

 private OnFragmentInteractionListener mListener;

//點擊事件後如果要傳的值就使用
 mListener.onFragmentInteraction("*");


    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mListener = (OnFragmentInteractionListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }


    public interface OnFragmentInteractionListener {
        public void onFragmentInteraction(String uri);
    }

}


//MainActivity
public class MainActivity extends BaseFragmentActivity implements  MainLeftFragment.OnFragmentInteractionListener{


//將要發生的事件寫在這
    @Override
    public void onFragmentInteraction(String uri) {
        Toast.makeText(this,uri,Toast.LENGTH_SHORT).show();
    }


}

星期、月份英文縮寫

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