/**
* @brief Action列表。
*/
private List<String> mActionList = new ArrayList<String>();
/**
* @brief Action处理线程。
*/
private CustomThread mActionListThread = new CustomThread() {
/**
* @brief 线程执行函数。
*/
protected void _execute() {
try {
synchronized(mActionList) {
//取得Action
if (mActionList.size() > 0) {
String data = mActionList.get(0);
if (data != null) {
mActionList.remove(0);
if (mAdapter.action(data) != true) {
Log.e(TAG, "_execute(): bad action! (" + data + ")");
}
}
else {
Log.e(TAG, "_execute(): data is null!");
}
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
};
---------------------------------------------
/**
* @brief 向Action队列发送Action函数。
* @param[in] action Action数据。
*/
private void _action(String action) {
if ((action != null) && (action.length() > 0)) {
synchronized(mActionList) {
//向Action队列中追加Action
mActionList.add(action);
}
}
else {
Log.e(TAG, "_action(): action is null!");
}
}
--------------------------------------
/**
* @brief Action广播监听器。
*/
private BroadcastReceiver mActionReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "onReceive() start");
if (intent != null) {
try {
String action = intent.getStringExtra("Action");
_action(action);
}
catch (Exception e) {
e.printStackTrace();
}
}
else {
Log.e(TAG, "onReceive(): intent is null!");
}
Log.d(TAG, "onReceive() end");
}
};