在activity的onCreate方法中,调用setContentView方法,其调用的是getWindow().setContentView()方法。
而getWindow()返回的Window 对象其实是Window抽象类的子类PhoneWindow.
mWindow = PolicyManager.makeNewWindow(this);
该句code是在Activity的attach()方法中调用。
private static String TAG = CameraTestActivity.class.getSimpleName();
private static String findSettableValue(Collection supportedValues,
String... desiredValues) {
String result = null;
if (supportedValues != null) {
for (String desiredValue : desiredValues) {
if (supportedValues.contains(desiredValue)) {
result = desiredValue;
break;
}
}
}
return result;
}
//调用:
1)
flashMode = findSettableValue(parameters.getSupportedFlashModes(),
Camera.Parameters.FLASH_MODE_TORCH, // string 常量"torch"
Camera.Parameters.FLASH_MODE_ON); // string常量"on"
2)
flashMode = findSettableValue(parameters.getSupportedFlashModes(),
Camera.Parameters.FLASH_MODE_OFF); // string常量"off"
Intent i=new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT,"这里是标题");
i.putExtra(Intent.EXTRA_TEXT, "这里是分享内容");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(i, "分享"));
//1)使用Intent的setComponent方法
Intent intent = new Intent();
intent.setComponent(new ComponentName(“包名”, “包名.主类名”));
intent.setAction(Intent.ACTION_VIEW);
startActivity(intent);
//2)使用包管理器
Intent intent = new Intent();
intent = getPackageManager().getLaunchIntentForPackage(“包名”);
startActivity(intent);
//1)定义一个排序的类:
private static class ByFirstStringComparator implements Comparator, Serializable {
@Override
public int compare(String[] o1, String[] o2) {
return o1[0].compareTo(o2[0]);
}
}
//2)使用:
Collections.sort(listArray, new ByFirstStringComparator());
private static Boolean isExit = false;
private static Boolean hasTask = false;
Timer tExit = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
isExit = false;
hasTask = true;
}
};
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
System.out.println("TabHost_Index.java onKeyDown");
if (keyCode == KeyEvent.KEYCODE_BACK) {
if(isExit == false ) {
isExit = true;
Toast.makeText(this, "再按一次后退键退出应用程序", Toast.LENGTH_SHORT).show();
if(!hasTask) {
tExit.schedule(task, 2000);
}
} else {
finish();
System.exit(0);
}
}
return false;
}
http://www.cnblogs.com/luxiaofeng54/archive/2011/05/03/2035392.html
方法为在XML文件内空白地方点击鼠标右键,选择 Source/Cleanup Document...
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.killBackgroundProcesses("name.of.your.package");
需要一个权限
KILL_BACKGROUND_PROCESSES
String sdk=android.os.Build.VERSION.SDK;// SDK号
String model=android.os.Build.MODEL; // 手机型号
String release=android.os.Build.VERSION.RELEASE;
// android系统版本号
// 获取手机的DeviceID,即手机的唯一标识。
// GSM网络:IMEI号
// ESN,CDMA网络:MEID号
// 获取不到时,返回null
// 需要权限:READ_PHONE_STATE
TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
String deviceId = tm.getDeviceId();
1) 创建Handler:
Handler mHandler = new Handler(){
public void handleMessage(Message msg){
swtich(msg.what){
case msgId:
// 消息为msgId的处理
break;
case msgId2:
// 消息为msgId2的处理
break;
default:
break;
}
}
}
2) 程序中发送消息:
Message m = new Message();
m.what=msgid;
handler.sendMessage(m);
如果需要传递数据,可以使用如下:
Bundle b = new Bundle();
b.putString(key,value);
b.putString(key1,value2);
m.setData(b);
handler.sendMessage(b);
1) 从文件中获取值:
// 得到SharePreferences对象,每个相同的sharedFileName返回的是相同的对象,即单例模式。
//0:Context.MODE_PRIVATE
//1:Context.MODE_WORLD_READABLE
//2:Context.MODE_WORLD_WRITEABLE
//3:Context.MODE_APPEND
//4:Context.MODE_MULTI_PROCESS
//8:Context.MODE_ENABLE_WRITE_AHEAD_LOGGING
SharedPreferences configSharedPref = mContext.getSharedPreferences("sharedFileName",0);
String str = configSharedPref.getString("key","defaultValue");
2) 修改保存的数据:
SharePreferences.Editor configEditor = configSharedPref.edit();
configEditor.putString("key","new value");
configEdit.commit();
Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,getString(R.string.app_name));
shortcutIntent.putExtra("duplicate", false);
Intent appIntent = new Intent(mContext, MainActivity.class);
appIntent.setAction("android.intent.action.MAIN");
appIntent.addCategory("android.intent.category.LAUNCHER");
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, appIntent);
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(mContext, R.drawable.icon);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,iconRes);
sendBroadcast(shortcutIntent);
boolean enabled = false;
WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
if (wifiManager != null) {
enabled = wifiManager.isWifiEnabled();
}
if(wifiManager.getConnectionInfo().getIpAddress() == 0) {
enabled = false;
}
}
String proxyHost = android.net.Proxy.getDefaultHost();
int port = android.net.Proxy.getDefaultPort();