1、sqlite中处理单引号:
所有单引号换成双单引号,如:
content.replace("'", "''");
这样是不行的,临时抱佛脚,换成了带"?"的通配形式
2、SimpleCursorAdapter 的 notifyDataSetChanged无效:
可以使用SimpleCursorAdapter 的changeCursor方法:
3、listview不显示分割线:
setDriver(null),或者在xml文件中属性设置为@null
4、sqlite 中replace into 无效:
之前写好的代码调试都通过了,今天突然发现不能运行了:sqlite,表中创建唯一索引,然后使用replace into实现插入或者更新,结果变成了只插入,折腾了几个小时,最后改掉了表中一个名为id的字段,实在是无语
5、临时写java的Thread封装:
package com.ttdevs.thread;
import android.os.Process;
public abstract class BaseThread extends Thread {
private volatile boolean mQuit = false;
public BaseThread() {
}
/**
* prepare if needed
*/
public boolean prepare() {
return true;
}
/**
* run body
*/
public abstract void execute();
/**
* recycle if needed
*/
public void recycle() {
}
/**
* stop thread
*/
public final void quit() {
mQuit = true;
interrupt();
}
@Override
public void run() {
// TODO
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
if (!prepare()) {
return;
}
while (true) {
try {
execute();
} catch (Exception e) {// } catch (InterruptedException e) {
if (mQuit) {
recycle();
return;
}
continue;
}
}
}
}
6、volley中设置连接超时:
/**
* Opens an {@link HttpURLConnection} with parameters.
* @param url
* @return an open connection
* @throws IOException
*/
private HttpURLConnection openConnection(URL url, Request<?> request) throws IOException {
HttpURLConnection connection = createConnection(url);
int timeoutMs = request.getTimeoutMs();
connection.setConnectTimeout(timeoutMs);
connection.setReadTimeout(timeoutMs);
connection.setUseCaches(false);
connection.setDoInput(true);
// use caller-provided custom SslSocketFactory, if any, for HTTPS
if ("https".equals(url.getProtocol()) && mSslSocketFactory != null) {
((HttpsURLConnection)connection).setSSLSocketFactory(mSslSocketFactory);
}
return connection;
}
HttpClientStack:
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
throws IOException, AuthFailureError {
HttpUriRequest httpRequest = createHttpRequest(request, additionalHeaders);
addHeaders(httpRequest, additionalHeaders);
addHeaders(httpRequest, request.getHeaders());
onPrepareRequest(httpRequest);
HttpParams httpParams = httpRequest.getParams();
int timeoutMs = request.getTimeoutMs();
// TODO: Reevaluate this connection timeout based on more wide-scale
// data collection and possibly different for wifi vs. 3G.
HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
HttpConnectionParams.setSoTimeout(httpParams, timeoutMs);
return mClient.execute(httpRequest);
}
/**
* Sets the retry policy for this request.
*/
public void setRetryPolicy(RetryPolicy retryPolicy) {
mRetryPolicy = retryPolicy;
}
RetryPolicy :
/**
* Retry policy for a request.
*/
public interface RetryPolicy {
/**
* Returns the current timeout (used for logging).
*/
public int getCurrentTimeout();
/**
* Returns the current retry count (used for logging).
*/
public int getCurrentRetryCount();
/**
* Prepares for the next retry by applying a backoff to the timeout.
* @param error The error code of the last attempt.
* @throws VolleyError In the event that the retry could not be performed (for example if we
* ran out of attempts), the passed in error is thrown.
*/
public void retry(VolleyError error) throws VolleyError;
}
7、android 与图片相关:
8、将eclipse项目中的文件夹移除SVN的控制(添加到svn:ignore)
9、屏幕旋转,activity的成员变量被全部释放?!
10、ViewPager频繁被回收
ViewPager
public void setOffscreenPageLimit (int limit)
Set the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state. Pages beyond this limit will be recreated from the adapter when needed.
This is offered as an optimization. If you know in advance the number of pages you will need to support or have lazy-loading mechanisms in place on your pages, tweaking this setting can have benefits in perceived smoothness of paging animations and interaction. If you have a small number of pages (3-4) that you can keep active all at once, less time will be spent in layout for newly created view subtrees as the user pages back and forth.
You should keep this limit low, especially if your pages have complex layouts. This setting defaults to 1.
Parameters
limit How many pages will be kept offscreen in an idle state.
11、android SQLite 分页查询,参数为页大小和起始编号
12、获取进程内存:
13、与联系人相关:
14、设置字体大小:
setTextSize(int unit, int size)
TypedValue.COMPLEX_UNIT_PX : Pixels
TypedValue.COMPLEX_UNIT_SP : Scaled Pixels
TypedValue.COMPLEX_UNIT_DIP : Device Independent Pixels