首先,我看了看这些;
我有将近一百万人使用的流应用程序。我正在为播放器使用前台服务。我还没有实现MediaSession。我有99.95%的无崩溃会话。因此,该应用程序适用于所有版本,但我开始使用Android 9获取崩溃报告(ANR)。此崩溃仅发生在Samsung手机上,尤其是s9, s9+, s10, s10+, note9型号。
我尝试过这些
startForeground()方法onCreate()Service.startForeground()之前致电Context.stopService()我阅读了Google开发人员的一些评论,他们说这仅仅是Intended Behavior。我想知道这是由三星的系统还是Android操作系统引起的。有人对此有意见吗?我怎样才能解决这个问题?
Message Gradle构建:
错误:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败。
java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex
这是gradle构建文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso
core:3.0.1'
implementation files('libs/bsh-core-2.0b4.jar')
implementation files('libs/selenium-java-2.3.0.jar')
implementation files('libs/selenium-remote-driver-3.0.0.jar')
// https://mvnrepository.com/artifact/io.appium/java-client
implementation group: 'io.appium', name: 'java-client', version: '5.0.4'
}
Run Code Online (Sandbox Code Playgroud) 如何处理获取同名但类型不同的字段?我在同一个请求中从 API 有时得到整数值有时是布尔值。我想知道当我得到这样的 Json 时如何处理。我创建了类型适配器但它不起作用
我想过创建不同的 POJO 类。但是这个问题不仅仅针对一个请求。由于这个原因,我不喜欢创建 POJO。顺便说一句,我看到了类似的问题,但它并没有解决我的问题。
{
"name" : "john doe",
"isValid" : true
}
Run Code Online (Sandbox Code Playgroud)
有时我得到 int
{
"name" : "john doe",
"isValid" : 1
}
Run Code Online (Sandbox Code Playgroud)
获取整数时出现意外的 json 异常
class XModel{
private boolean isValid;
...
...
}
Run Code Online (Sandbox Code Playgroud)
我想为每个请求返回一个布尔值。有谁知道如何解决这个问题?
编辑:我想通过类型适配器阻止 instanceOf 关键字
解决方案:@Micha?Ziober 的回应对我有用。
class BooleanJsonDeserializer implements JsonDeserializer<Boolean> {
private final Set<String> TRUE_STRINGS = new HashSet<>(Arrays.asList("true", "1", "yes"));
@Override
public Boolean deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
System.out.println(json);
JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive();
if (jsonPrimitive.isBoolean()) { …Run Code Online (Sandbox Code Playgroud) 我有一个基于 MVVM 架构的应用程序。我有两个模块,存储库和数据源。并使用协程。我在 Github 上遇到了一些项目,它们采用了不同的方式。
我的实现是这样的;
You can think naming as login, profile etc. instead of X letter
Run Code Online (Sandbox Code Playgroud)
数据源接口
interface IXDatasource{
suspend fun fetchData(): LiveData<XResponse>
}
Run Code Online (Sandbox Code Playgroud)
数据源实现
class XDatasourceImp @Inject constructor(private val apiService: ApiService) : IXDatasource{
suspend fun fetchData(): LiveData<XResponse> {
// getting data
return xResponse
}
}
Run Code Online (Sandbox Code Playgroud)
存储库接口
interface XRepository {
suspend fun getXData(): LiveData<XResponse>
}
Run Code Online (Sandbox Code Playgroud)
存储库实现
class XRepositoryImp @Inject constructor(private val iDatasource: IXDatasource): XRepository {
override suspend fun getXData(): LiveData<XResponse> {
return withContext(Dispatchers.IO) {
iDatasource.fetchData()
}
}
} …Run Code Online (Sandbox Code Playgroud)