在Activity中加入Scheme桌面图片不见问题:
在里面在创建一个<inter-filter>属性
<activity
android:name="com.linghang.app.activity.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustPan"
android:configChanges="keyboard|navigation|orientation|keyboardHidden|uiMode|screenSize"
android:theme="@style/startingTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter >
<data android:scheme="cfetc"/>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
2.viewpager设置不能左右滑动,但是里面的能够滑动解决办法在拦截器和onTouchEvent事件里加一个布尔变量
public class CanScrollViewPager extends ViewPager {
private boolean isScrollAble=false;
//防止viewpager滑动左右滑动,但是里面还是可以滑动
public CanScrollViewPager(@NonNull Context context) {
this(context, null);
}
public CanScrollViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return isScrollAble&&super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
return isScrollAble&&super.onTouchEvent(ev);
}
//解决viewPager里面的recyclerView是水平滑动的时候,防止滑动到最右边或最左边时候viewpager会跟随滑动
@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
if (v.getVisibility() != VISIBLE) {
return false;
}
if (v != this && v instanceof RecyclerView
&& ((RecyclerView) v).getLayoutManager() instanceof LinearLayoutManager
&& ((LinearLayoutManager) ((RecyclerView) v).getLayoutManager()).getOrientation() == LinearLayoutManager.HORIZONTAL) {
return true;
}
return super.canScroll(v, checkV, dx, x, y);
}
}
3.单例模式:在使用的时候最好在写一个释放方法,防止下次进来时导致上次的实例没有释放,导致初始化数据时候初始化不了
//在使用静态类时,使用完调用这个释放,防止下次进来不会初始化
public synchronized void release() {
if (mList != null) {
mList.clear();
}
mList = null;
mAutoTextMdManager = null;
}
4.ViewPager+Fragment配合使用的时候会内存泄漏如下图
解决办法在PagerAdapter写一个释放方法给外部调用如图
在外部Activity的onDestroy中把vp绑定的Adapter置空如图
5.在多次打开同一个Activity中造成多次add一个Fragment也会内存泄漏如下图
解决办法
在ondestroy中写后面两句代码mTransaction.remove(fragment)先移除,在销毁mTransaction.detach(fragment)
遇到依赖包冲突的解决办法
1.直接把你的不一致的系列改为和依赖的一致
2.直接删除依赖,重新下载工程下来复制里面的文件在你的工程里面,
3.强行统一版本
在工程build.gradle目录下添加
ext{
SDK版本 = 28
编译工具版本 = "$SDK版本.0.3"
最低兼容版本 = 16
}
subprojects{
afterEvaluate {
if(it.hasProperty('android')){
android {
compileSdkVersion rootProject.ext.SDK版本
buildToolsVersion rootProject.ext.编译工具版本
defaultConfig {
minSdkVersion rootProject.ext.最低兼容版本
targetSdkVersion rootProject.ext.SDK版本
}
}
}
}
}
再在项目的build.gradle下添加
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion "$rootProject.ext.SDK版本.+"
}
}
}
}
解决android9.0 http不能通信问题,三种解决办法分别如下:
- APP改用https请求
- targetSdkVersion 降到27以下
- 在 res 下新增一个 xml 目录,然后创建一个名为:network_security_config.xml 文件(名字自定) ,内容如下,大概意思就是允许开启http请求
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted ="true"/>
</network-security-config>
然后在APP的AndroidManifest.xml文件下的application标签增加以下属性
<application
...
android:networkSecurityConfig="@xml/network_security_config"
...
/>
GreenDao出现Entity is detached from DAO context 问题解决
直接点击LogCat上面显示错误,看定位到那一行,直接看entity生成greenDao语法如下
其实已经很明确的告诉你是什么问题了,不要看它抛出异常的注释直接看if(choiceOptionList==null)这一句就知道答案,就是服务器返回给你的choiceOptionList是一个null导致的问题,解决办法直接叫后台不要返回一个null的choiceOptionList数组,要么返回空数组,要么返回有数据的数组,或者是你自己本地保存数据赋值的时候不要把choiceOptionList设置null,直接赋值一个空数组,或者有数据的数组,就能解决问题。
开发中遇到More than one file was found with OS independent path 'lib/arm64-v8a/libc++_shared.so'
解决办法在app的目录的build.gralde中添加以下代码把后面的so替换为你的重复的so库就行,意思是如果出现多个so库只优先保留第一个so
packagingOptions{
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/x86_64/libc++_shared.so'
pickFirst 'lib/x86/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
}
Retrofit上传图片带有字符串参数多出一个引号的问题解决方法如下
使用注解@Part的时候这里定义的String类型改为RequestBody,在传参的地方将该参数用RequestBody.create(MediaType.parse("text/plain"), value)转换为RequestBody传入解决带有引号。