加入此行(addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)),每次按tab鍵就會重整.
example:
new Intent(this,X.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
2013年5月31日 星期五
2013年5月29日 星期三
(Android Note) is not valid; is your activity running?
由於父activity包含子activity,但是子的activity要產生一個new AlertDialog.Builder(this),此時就會發生錯誤。
解決方式,把this改成指向父節點getParent()。
解決方式,把this改成指向父節點getParent()。
2013年2月28日 星期四
android:Theme 用法
說明
(1) /res/values/目錄, 預設的styles.xml
<resources>
<style name="AppTheme" parent="android:Theme.Black" />
</resources>
(2) 參數
android:theme="Theme.Light" //背景為白色
android:theme="Theme.Light.NoTitleBar" //白色背景並無標題欄
android:theme="Theme.Light.NoTitleBar.Fullscreen" //白色背景,無標題欄,全螢幕
android:theme="Theme.Black" //背景黑色
android:theme="Theme.Black.NoTitleBar" //黑色背景,無標題欄
android:theme="Theme.Black.NoTitleBar.Fullscreen" //黑色背景,無標題欄,全螢幕
android:theme="Translucent" //半透明
android:theme="Theme.Translucent.NoTitleBar"
android:theme="Theme.Translucent.NoTitleBar.Fullscreen"
android:theme="Theme.Panel"
android:theme="Theme.Light.Panel"
android:theme="@android:style/Theme.Dialog" //將一個Activity顯示為話框模式
android:theme="@android:style/Theme.NoTitleBar" //無標題欄
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" //無標題欄,全螢幕
android:theme="Theme.Wallpaper" //系統桌面為應用程式背景
android:theme="Theme.Wallpaper.NoTitleBar" //系統桌面為應用程式背景,無標題欄
android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" //系統桌面為應用程式背景,無標題欄,全螢幕
(1) /res/values/目錄, 預設的styles.xml
<resources>
<style name="AppTheme" parent="android:Theme.Black" />
</resources>
(2) 參數
android:theme="Theme.Light" //背景為白色
android:theme="Theme.Light.NoTitleBar" //白色背景並無標題欄
android:theme="Theme.Light.NoTitleBar.Fullscreen" //白色背景,無標題欄,全螢幕
android:theme="Theme.Black" //背景黑色
android:theme="Theme.Black.NoTitleBar" //黑色背景,無標題欄
android:theme="Theme.Black.NoTitleBar.Fullscreen" //黑色背景,無標題欄,全螢幕
android:theme="Translucent" //半透明
android:theme="Theme.Translucent.NoTitleBar"
android:theme="Theme.Translucent.NoTitleBar.Fullscreen"
android:theme="Theme.Panel"
android:theme="Theme.Light.Panel"
android:theme="@android:style/Theme.Dialog" //將一個Activity顯示為話框模式
android:theme="@android:style/Theme.NoTitleBar" //無標題欄
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" //無標題欄,全螢幕
android:theme="Theme.Wallpaper" //系統桌面為應用程式背景
android:theme="Theme.Wallpaper.NoTitleBar" //系統桌面為應用程式背景,無標題欄
android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" //系統桌面為應用程式背景,無標題欄,全螢幕
2013年1月15日 星期二
(Android Note) 驗證是否有網路連線
1. code
//判斷當前網路連接狀態 、0 無連接 、1 3G、2 WIFI
public static int checkNetworkInfo(Context context){
int stateType = 0;
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
State mobile =
cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); //取得3G連線狀態
State wifi =
cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); //取得WIFI連線狀態
if (mobile == State.CONNECTED || mobile == State.CONNECTING){
stateType = 1;
}
if (wifi == State.CONNECTED || wifi == State.CONNECTING){
stateType = 2;
}
return stateType;
}
- *AndroidManifest 開啟權限
- <uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE" /> //訪問存取網路狀態許可權限
- <uses-permissionandroid:name="android.permission.ACCESS_WIFI_STATE" /> //訪問存取wifi狀態許可權限
- <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> //訪問存取手機狀態許可權限
(Android Note) AlertDialog.Builder
1. Code
final AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle(" Test ");
builder.setMessage(" Test ");
builder.setIcon(android.R.drawable.ic_dialog_alert);
//3種事件處理方式
builder.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setNegativeButton("Cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.setNeutralButton("other things", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.show();
final AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle(" Test ");
builder.setMessage(" Test ");
builder.setIcon(android.R.drawable.ic_dialog_alert);
//3種事件處理方式
builder.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setNegativeButton("Cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.setNeutralButton("other things", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.show();
2013年1月3日 星期四
(Android Note) 內部和外部儲存空間大小
1. Code
(1) sdcard 是否存在
android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
return true; //存在
return false; //不存在
(2) 內部儲存空間
File path = android.os.Environment.getDataDirectory();
StatFs sf = new StatFs(path.getPath());
long bs = sf.getBlockSize();
long ab = stat.getAvailableBlocks();
long bc = stat.getBlockCount();
retrun bs*ab; //剩餘儲存空間
retrun bs*bc; //總儲存空間
(3) sdcard儲存空間
File path = android.os.Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(path.getPath());
long bs = sf.getBlockSize();
long ab = stat.getAvailableBlocks();
long bc = stat.getBlockCount();
retrun bs*ab; //剩餘儲存空間
retrun bs*bc; //總儲存空間
2. 說明
bs(block size),在fat32檔案系統, block size是 4096 byte,其他可以用getBlockSize()來找出block size 大小。
(1) sdcard 是否存在
android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
return true; //存在
return false; //不存在
(2) 內部儲存空間
File path = android.os.Environment.getDataDirectory();
StatFs sf = new StatFs(path.getPath());
long bs = sf.getBlockSize();
long ab = stat.getAvailableBlocks();
long bc = stat.getBlockCount();
retrun bs*ab; //剩餘儲存空間
retrun bs*bc; //總儲存空間
(3) sdcard儲存空間
File path = android.os.Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(path.getPath());
long bs = sf.getBlockSize();
long ab = stat.getAvailableBlocks();
long bc = stat.getBlockCount();
retrun bs*ab; //剩餘儲存空間
retrun bs*bc; //總儲存空間
2. 說明
bs(block size),在fat32檔案系統, block size是 4096 byte,其他可以用getBlockSize()來找出block size 大小。
2012年12月12日 星期三
(Android Note) 畫面横屏OR值屏
1. code
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//畫面直向
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//畫面橫向
以上畫面只要轉方向時,activity 會重新執行。
- 如果不要 activity 重新執行,需要在 AndroidManifest.xml 檔案中,在 activity 加入 android:configChanges="orientation|keyboardHidden" 就會禁止重新執行。
訂閱:
文章 (Atom)