8.子线程中Toast消息使用格式:
Looper.prepare();
Toast.makeText(ActivityImportCourses.this,"导入失败!",Toast.LENGTH_LONG).show();
Looper.loop();
但这几行语句后面的代码都不会执行。
9.最简AnsycTask格式:
new AsyncTask<Void,Void,Void>(){
@Override
protected Void doInBackground(Void... params) {
return null;
}
}.execute();
doInBackground方法在子线程中执行,其他方法在主线程中执行。
其中Void是java.lang.Void,一种类型,与void不同,详细请见https://stackoverflow.com/questions/10839042/what-is-the-difference-between-java-lang-void-and-void。
10.socket编程输出流,
os = socket.getOutputStream();
pw = new PrintWriter(os, true);
PrintWriter的第二个参数值表示是否autoFlush,autoFlush则自动将缓冲流刷新到输出流,否则要在后面加上pw.flush(),java中的输出流都要flush才能写入。
11.android.os.CounDownTimer类,用于计时,取消计时用方法后置空才有效
timer.cancel();
timer=null;
12.Fragment,onResume、setUserVisibleHint、onHiddenChanged 和 onViewCreated 用于监听页面浏览,执行FragmentTransaction的hide和show方法时才执行onHidenChaged方法。