1. 程式人生 > >Android之零碎記憶點

Android之零碎記憶點

WindowManager wm = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE));


Cursor cursor = getContentResolver().query(People.CONTENT_URI, null, null, null, null); 

解釋:Cursor cursor = getContentResolver().query(People.CONTENT_URI, null, null, null, null);先獲得一個指向系統通訊錄資料庫的Cursor物件獲得資料來源。


startManagingCursor(cursor); 

[size=medium]解釋:This method allows the activity to take care of managing the given Cursor's lifecycle for you based on the activity's lifecycle. That is, when the activity is stopped it will automatically call deactivate() on the given Cursor, and when it is later restarted it will call requery() for you. When the activity is destroyed, all managed Cursors will be closed automatically.
startManagingCursor(cursor);我們將獲得的Cursor物件交由Activity管理,這樣Cursor的生命週期和Activity便能夠自動同步,省去自己手動管理Cursor。
[/size]


newfs_msdos /dev/block/mmcblk3p2
清資料


ListAdapter listAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_expandable_list_item_1,   
cursor,
new String[]{People.NAME},
new int[]{android.R.id.text1});

[size=medium]解釋:SimpleCursorAdapter 建構函式前面3個引數和ArrayAdapter是一樣的,最後兩個引數:一個包含資料庫的列的String型陣列,一個包含佈局檔案中對應元件id的int型陣列。其作用是自動的將String型陣列所表示的每一列資料對映到佈局檔案對應id的元件上。上面的程式碼,將NAME列的資料一次對映到佈局檔案的id為text1的元件上。[/size]


mTextViews[1].setTextAppearance(mContext,
android.R.attr.textAppearanceSmall)

[size=medium]解釋:[quote]Text color, typeface, size, and style for "small" text.

public static final int textAppearanceSmall
Since: API Level 1

Text color, typeface, size, and style for "small" text. Defaults to secondary text color.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".
Constant Value: 16842818 (0x01010042)[/quote]

詳見:[/size][url]http://androidappdocs.appspot.com/reference/android/R.attr.html[/url]


[size=medium]動態新增perssion:[/size]
[quote]許可權樹(permission-tree)
許可權樹的設定是為了統一管理一組許可權,聲明於該樹下的許可權所有者歸屬該應用。系統提供了API,應用可以在執行時動態新增。
 PackageManager.addPermission()[/quote]

得到PackageName的方式:
1
ActivityManager mActivityManager;
List<ActivityManager.RunningServiceInfo> mList;

mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
mList = mActivityManager.getRunningServices(20);
for(ActivityManager.RunningServiceInfo am : mList) {
datas.add(am.service.getPackageName());
}

2
intent.getComponent().getPackageName()


3
am.baseActivity.getPackageName()

[img]http://dl.iteye.com/upload/attachment/341422/8a49f1f5-2961-370d-8ce0-cbf400349beb.png[/img]

[size=large]killBackgroundProcesses[/size]
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
am.killBackgroundProcesses("cn.com.android123.cwj");



 ActivityManager.RunningAppProcessInfo runinfo

pm = ctx.getApplicationContext().getPackageManager()


[url]http://t.baidu.com/guide/avatar[/url]


清資料
newfs_msdos /dev/block/mmcblk3p2


[size=medium]【讓本view位於父view的橫向中間】[/size]
android:layout_gravity="center_horizontal"