存儲目錄:
Enviroment.getDataDirecotry();
Enviroment.getExternalStorageDirectory();
Enviroment.getExternalStorageState();
if(externalState.equals(Enviroment.MEDIA_MOUNTED)){
}
SharedPreferences類似於localStorage
SharedPerferences sp=getSharedPreferences("local",MODE_PRIVATE);
Editor editor=sp.edit();
editor.putString("username",username);
editor.commit();
使用:
sp.getString("username","");
XmlSerializer serializer=Xml.newSerializer();
XmlPullParser parser=Xml.newPullParser();
if(eventType !=XmlPullParser.END_DOCUMENT){
parser.next();
}
SQLiteOpenHelper
一般繼承這個類實現相關事件的處理
dbHelper.getWritableDatabase();
dbHelper.getReadableDatabase();
ListView,ListAdapter
自定義List,通過ListAdapter的getView中操作
if(convertView==null){
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(android.R.layout.item,null);
convertView=view;
}
...setText();
...setText();
return convertView;
ArrayList<HashMap<String,Object>>datas=new ArrayList<HashMap<String,Object>>();
SimpleAdapter adapter=new SimpleAdapter(
this,
datas,
R.layout.lv_item_layout,
new String[]{"圖片","文字"},
new int[]{R.id.iv,R.id.tv}
);
lv.setAdapter(adapter);
HttpURLConnection conn =(HttpURLConnection)url.openConnection();
Bitmap bitmap=BitmapFactory.decodeStream(is);
runOnUiThread(new Runnable(){
});
消息處理:
主線程中new一個Handler處理消息
子線程中new Message();並用mHandler.sendMessage(msg);
smartImageView底層用的是HttpURLConnection,可以與HttpURLConnection共享session
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
if(conn.getResponseCode()==200){
}
POST
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length",params.getBytes().length+"");
conn.setDoOutput(true);
conn.getOutputStream().wirte(params.getBytes());
分段下載
1、conn.getContentLength();
2、conn.setRequestProperty("Range","bytes=100-200");
RandomAccessFile raf=new RandomAccessFile(file,"rw");
隱式意圖:用於垮應用打開Activity
Activity的返回值:
父Activity:startActivityForResult(intent,11111);
子Activity,setResult(11111,intent);
父Activity,onActivityResult
啓動服務:
startService(intent);
stopService(intent);
websocket組件:
Java-websocket