Cordova插件开发

/*输出日志
Log.v(String tag, String msg);//Verbose
Log.d(String tag, String msg);//Debug
Log.i(String tag, String msg);//Info
Log.w(String tag, String msg);//Warning
Log.e(String tag, String msg);//Error
*/

/*线程间传递消息*/
private static final int ERROR = 1;
private Handler mHandler = new Handler() {
public void handleMessage(Message msg, String strInfo) {
switch (msg.what) {
case ERROR:
showMessage(msg.getData().getString("Error"));
default:
break;
}
}

};
/*主线程中弹出消息框*/
private void showMessage(String strMsg) {
AlertDialog.Builder builder = new Builder(mContext);
builder.setTitle("提示");
builder.setMessage(strMsg);
// 稍后更新
builder.setNegativeButton("确定", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
Dialog noticeDialog = builder.create();
noticeDialog.show();
}
/*子线程中调用pushMsg向主线程发送数据*/
private void pushMsg(String info){
Message msg = new Message();
msg.what = ERROR;
Bundle bundle = new Bundle();
bundle.putString("Error", info);
msg.setData(bundle);//mes利用Bundle传递数据
mHandler.sendMessage(msg);
}






























原文地址:https://www.cnblogs.com/Full--Stack/p/8041681.html