出现空指针问题
clear rebuild即可
Android studio terminal 设置中文
git config --global i18n.commitencoding utf-8
git config --global i18n.logoutputencoding utf-8
set LESSCHARSET=utf-8
git reset -- hard
更新全部代码到最新
git checkout -- ./**
单独更新某一个目录
还原当前分支代码
git checkout -f && git clean -df
git reset --hard && git clean -df
MVP :
优点:分离M层和V层的代码,P层建立关联,实现M层和V层的解耦。
缺点:每增加一个功能,需要增加相应的接口回调。
核心:接口实现隔离,业务层交给P层。p层的逻辑处理单一的功能,不要融合一个模块下的增删改查的整个功能。
由于p层持有了v层的引用,通常在p层使用弱引用来持有view层实例,在p层销毁的时候需要将v层的引用销毁掉。
契合类指的p层和v层的接口类放在一个contract接口类中,契合类方便管理业务层的功能,将单个功能放到一个contract契合类中。
public interface AddBookShelfContract {
interface View extends BaseContract.BaseView {
void addBookShelfSuccess(BookShelfItem... bookShelfItem);
void addBookShelfFail();
}
interface Presenter extends BaseContract.BasePresenter<View> {
void addBookShelf(String tokenId, BookShelfItem... bookShelfItem);
}
}
MVVM:观察者模式,通过数据的改变来通知相应的View改变的过程。M层和上面的MVP中的M层是一样的,都是网络请求+数据缓存来实现该层的,里面的双V,一个指的ViewModel实现的,另外一个AndroidDataBinding实现V层,ViewModel层获取到M层的数据后,通过观察者模式通知AndroidDataBinding在UI上的改变。
打开cmd
adb tcpip 8888 重置端口
adb devices 查看设备
adb connect xxx:8888 连接
adb disconnect xxx:8888 断开
出现error: device not found
adb nodaemon server 检查5037端口
cannot bind 'tcp:5037' 5037端口被占用
netstat -ano | findstr "5037" 查看是什么进程占用5037端口
tasklist | findstr "18728" 查看这个进程是由哪个程序创建
taskkill /f /pid 18728 将adb进程结束掉
pm path com.wologic.wms
package:/data/app/com.wologic.wms-pHfDy8o7QTt7FXdBu3HK0g==/base.apk
adb shell am broadcast -a com.android.test --es test_string "this is test string" --ei test_int 100 --ez test_boolean true
String类型,int类型,boolean类型
应用安装失败,使用install安装,查看报错
adb install Android_65632.apk
adb shell am start -S -W com.wologic.wms/.activity.LoginActivity
String temp = etBoxCode.getText().toString();
String[] array = temp.split("[;]");
BoxCode = array[0];
String[] s1 = new String[]{"qqqq","qqqqaa","ddddd"};
Log.e(TAG, "doUpdate: " + new Gson().toJson(s1));
["qqqq","qqqqaa","ddddd"]
//第二种方式
List<String> list = new ArrayList<>();
for (int i = 0; i < list2.size(); i++) {
list.add(list2.get(i).getBoxCode());
}
Log.e(TAG, "doUpdate: " + new Gson().toJson(list));
["qqqq","qqqqaa","ddddd"]
//第三种方式
List<ClassBean> list = new ArrayList<>();
ClassBean bean = new ClassBean();
bean.setName("xiaoming");
list.add(bean);
Log.e(TAG, "doUpdate: " + new Gson().toJson(list));
[{"name":"xiaoming"}]
String[] perms = {Manifest.permission.CAMERA};
private void verifyPermission() {
int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
if (permission != PermissionChecker.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, perms, 0X01);
}
}
& | 左边无论真假,右边都进行计算
&& || 左边为假(真),右边不进行计算
&
只有1&1得1,其他得0,同理可得6&5算出二进制得100
1001 & 110 = 0000
1001 & 111 = 0001
1111 & 110 = 0110
1111 & 111 = 0111
10 -1 = 9 即是 1001
00不能起作用更容易碰撞。
16 -1 = 15 即是 1111
11,能起作用更不容易碰撞。
hashmap,空间换时间。0.75, 2倍。
|
只有0|0时候为0 ,其他为1
6|5等于7
^
任何相同二进制异或运算都得0
1^1=0,0^0=0
不相同的异或运算都得1
1^0=1,0^1=1
6的二进制为110,5的二进制为101
同理6^5的011
~
1变成0,0变成1
<<
空缺补0,被移除的高位丢弃
3<<2则是3*2*2也就是3乘以2的2次幂
>>
最高位是什么就补什么
3>>1则是3/2也就是3除以2的1次幂
无符号右移
无论高位是0还是1都补0
sparsearray,内存节约,key只能是int
get()二分查找,速度不会慢value,
delete()设置delete标志位,使用时赋值,不会真正删除,复用
arraycope,向后推移
int[5] mKey
object[5] mValue
arraymap,simplearraymap,== hashmap + sparsearray
追加:+1
new Random().nextInt(5)
Gson gson = new Gson();
Type type = new TypeToken<TestAlbum>() {
}.getType();
TestAlbum testAlbum = gson.fromJson(Utils.getApp().getString(R.string.free_music_json), type);
<string name="free_music_json">
"{
\"data\": [{
\"id\": 6,
\"link\": \"\",
\"name\": \"面试\",
\"order\": 1,
\"visible\": 1
}, {
\"id\": 9,
\"link\": \"\",
\"name\": \"Studio3\",
\"order\": 1,
\"visible\": 1
}, {
\"id\": 5,
\"link\": \"\",
\"name\": \"动画\",
\"order\": 2,
\"visible\": 1
}, {
\"id\": 1,
\"link\": \"\",
\"name\": \"自定义View\",
\"order\": 3,
\"visible\": 1
}, {
\"id\": 2,
\"link\": \"\",
\"name\": \"性能优化 速度\",
\"order\": 4,
\"visible\": 1
}, {
\"id\": 3,
\"link\": \"\",
\"name\": \"gradle\",
\"order\": 5,
\"visible\": 1
}, {
\"id\": 4,
\"link\": \"\",
\"name\": \"Camera 相机\",
\"order\": 6,
\"visible\": 1
}, {
\"id\": 7,
\"link\": \"\",
\"name\": \"代码混淆 安全\",
\"order\": 7,
\"visible\": 1
}, {
\"id\": 8,
\"link\": \"\",
\"name\": \"逆向 加固\",
\"order\": 8,
\"visible\": 1
}],
\"errorCode\": 0,
\"errorMsg\": \"\"
}"
</string>
String JsonData = util.getJson(this, "test");//获取assets目录下的json文件数据
Gson gson = new Gson();
testBean testBean = gson.fromJson(JsonData, testBean.class);
for (com.example.test_master.testBean.DataDTO datum : testBean.getData()) {
Log.e(TAG, "initView: " + datum.getName());
}
public static String getJson(Context context, String fileName) {
StringBuilder stringBuilder = new StringBuilder();
try {
AssetManager assetManager = context.getAssets();
BufferedReader bf = new BufferedReader(new InputStreamReader(assetManager.open(fileName)));
String line;
while ((line = bf.readLine()) != null) {
stringBuilder.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
return stringBuilder.toString();
}
asset.test.txt
{"data":[{"id":6,"link":"","name":"面试","order":1,"visible":1},{"id":9,"link":"","name":"Studio3",
"order":1,"visible":1},{"id":5,"link":"","name":"动画","order":2,"visible":1},{"id":1,"link":"",
"name":"自定义View","order":3,"visible":1},{"id":2,"link":"","name":"性能优化 速度","order":4,"visible":1},
{"id":3,"link":"","name":"gradle","order":5,"visible":1},{"id":4,"link":"","name":"Camera 相机",
"order":6,"visible":1},{"id":7,"link":"","name":"代码混淆 安全","order":7,"visible":1},{"id":8,
"link":"","name":"逆向 加固","order":8,"visible":1}],"errorCode":0,"errorMsg":""}
接受方
AndroidManifast
<uses-permission android:name="com.wologic.wms.broadcast.QRBroadcastReceiver.ACTION" />
<permission android:name="com.wologic.wms.broadcast.QRBroadcastReceiver.ACTION" />
<receiver
android:name=".broadcast.QRBroadcastReceiver">
<intent-filter>
<action android:name="com.wologic.wms.broadcast.QRBroadcastReceiver.ACTION" />
</intent-filter>
</receiver>
public static final String BROADCAST_ACTION = "com.wologic.wms.broadcast.QRBroadcastReceiver.ACTION";
if (intent.getAction().equals(BROADCAST_ACTION)) {
String qrData = intent.getStringExtra("QR_DATA");
Log.e("测试接收到广播:", qrData);
}
发送方
Intent intent = new Intent();
intent.setAction(BROADCAST_ACTION);
intent.putExtra("QR_DATA", result.getText());
intent.setComponent(new ComponentName("com.wologic.wms","com.wologic.wms.broadcast.QRBroadcastReceiver"));
sendBroadcast(intent);
//KeyEvent.KEYCODE_MENU
//KeyEvent.KEYCODE_BACK
public static void sendKeyEvent(final int KeyCode) {
new Thread() { //不可在主线程中调用
public void run() {
try {
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyCode);
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}