我正在尝试使用 OkHttp 通过使用拦截登录到 Crashlytics,因为我的一些客户收到 500 错误,我想完成他们发布的内容和在响应中获得的详细信息。就像 Android Studio 的日志中显示的 OkHttp 一样。
当发生 200 错误但没有成功时,我尝试记录详细信息。
@Module
public class DIModule {
MyApplication application;
public DIModule(MyApplication application) {
this.application = application;
}
public DIModule()
{
}
@Singleton
@Provides
OkHttpClient getOkHttpClient() {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
return new OkHttpClient.Builder()
.addInterceptor(logging).addInterceptor(new HeaderInterceptor())
.build();
}
@Singleton
@Provides
Retrofit getRetro(OkHttpClient client) {
return new Retrofit.Builder()
.baseUrl(Api.BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create()) //Here we are using the GsonConverterFactory to directly convert json data to object
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
}
@Singleton …Run Code Online (Sandbox Code Playgroud) 我的目标是:
当前设置:
subscribe()并可以抛出Crashlytics.logException(t)此设置的问题是 Firebase Crashlytics 将几乎所有错误归入 RxTracer 下 TracingObserver.java – line 2 - com.halfhp.rxtracer.TracingObserver.
我找不到任何方法将自定义分组等添加到 Firebase Crashlytics
你们如何向 Firebase Crashlytics 报告 RxJava 错误?
在我的聊天应用程序中,我想从本地数据库读取消息并由工作经理将它们发送到服务器,并在用户发送新消息时进行改造。
在父母中:
OneTimeWorkRequest workRequest = new OneTimeWorkRequest
.Builder(SendMsg_Work.class)
.setConstraints(new Constraints
.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build())
.setInitialDelay(5, TimeUnit.SECONDS)
.setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 30, TimeUnit.SECONDS)
.build();
WorkManager.getInstance().enqueue(workRequest);
Run Code Online (Sandbox Code Playgroud)
在工人:
@NonNull
@Override
public Result doWork() {
ChatRoom_Model_Local ll = database.get_unSendMsg();
if (ll != null) {
sendMessage(ll);
} else {
return Result.failure();
}
}
Run Code Online (Sandbox Code Playgroud)
和改造 - 我也使用 RxJava :
private void sendMessage(ChatRoom_Model_Local model) {
Single<Response<MSG_Response>> api = ApiClient.createService(ApiInterface.class, pr.getData(pr.SendMessage_url))
.sendMSG(pr.getData(pr.MY_TOKEN), model.getOther_user(), model.getMsg_text());
api.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SingleObserver<Response<MSG_Response>>() {
@Override
public void onSubscribe(Disposable d) { }
@Override
public void onSuccess(Response<MSG_Response> response) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Rx3 中找到 subscribeOn 的主线程
Single.just(getHeavyData())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Data>() {
@Override
public void accept(Data d) throws Throwable {
setAdapters(d);
}
});
Run Code Online (Sandbox Code Playgroud)
AndroidSchedulers.mainThread() - 与全新的 RX3 不兼容
Gradle导入: implementation "io.reactivex.rxjava3:rxjava:3.0.0-RC3"
我们如何找到主线程以对 UI 进行更改?
我的应用程序弹出ANR(应用程序没有响应)对话框。很长一段时间以来,我都在努力解决这个问题。我做了很多优化,最后我的主线程需要 2~300 万微秒,但这还不够。
几乎所有的服务调用都是用 Rxjava 完成的。我不知道回调是否属于他们。
当我将Android Profiler用于显示弹出窗口的特定活动时,有2 个进程花费的时间太长。
第二个是handleCallback。我无法减少这些过程的时间。我不知道该怎么做以及它是什么。
我尝试使用异步任务,但即使我取得了一些成果,仍然有同样的问题。
更新:
当它弹出ANR 对话框时,我杀死了该应用程序 ,这些是最后的日志行:
2019-11-27 16:36:53.856 13843-14117/br.com.gomus.androidapp D/DownloadInteractor: addSongDownloadedToCurrentPlaylist
2019-11-27 16:36:53.858 13843-14117/br.com.gomus.androidapp D/DownloadRepositoryImpl: File download and update status finished, should verify all files download status
2019-11-27 16:36:53.860 13843-14117/br.com.gomus.androidapp D/DownloadRepositoryImpl: File download and update status concluded with success emitting progress
2019-11-27 16:36:53.863 13843-14117/br.com.gomus.androidapp D/DownloadRepositoryImpl: mItemsDownloaded: 4 mTotalItems14 …Run Code Online (Sandbox Code Playgroud) 我在我的项目中将 RxJava3 与 Room 一起使用,但出现以下错误
错误:不确定如何将 Cursor 转换为该方法的返回类型 (io.reactivex.rxjava3.core.Flowable>)
下面是我收到错误的 DAO 接口方法
@Query("SELECT * FROM wishlist_table")
Flowable<List<WishListMovie>> getWishList();
Run Code Online (Sandbox Code Playgroud)
我想可能是因为我在成绩文件中使用了以下依赖项:
implementation "androidx.room:room-rxjava2:$room_version"
Run Code Online (Sandbox Code Playgroud)
我试图找到 RxJava 3 的上述依赖项,但我找不到它。
我想知道如何在 Room 中使用 RxJava 3 或者我应该在我的项目中使用 RxJava 2。
我正在编写一个基于 Rx 的单向 UI 流,其中每个状态 reduce 是一个Single. 通常这样的流程已经完成scan(它们需要先前的状态),但是当Single涉及到时它有点棘手。我设法让它像这样工作:
val events = Observable.just("event1", "event2", "event3")
val initialState = Single.just(emptyList<String>())
// given a current state produces next state's Single
val reducer = { currentState: List<String>, event: String ->
Single.fromCallable { /* do work */ currentState.plus(event) }
}
events
.scan(
initialState,
{ currentStateSingle, event ->
val nextStateSingle = currentStateSingle
.flatMap { curState -> reducer(curState, event) }
// cache is required to avoid resubscription
// to all previously …Run Code Online (Sandbox Code Playgroud) 方法的调用者,
for (String name : controllerToPartitionModels.keySet())
{
List<PartitionModel> partitionsList = controllerToPartitionModels.get(name);
refreshPartition(partitionsList,false);
}
Run Code Online (Sandbox Code Playgroud)
方法
private void refreshPartition(List<PartitionModel> partitionModels, boolean isSyncAll) {
ITModule.getITService()
.refreshPartitionStatus(new ArrayList<>(partitionModels), isSyncAll)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io())
.subscribe(new Action() {
@Override
public void run() throws Exception {
Logger.get().d(ATTActionManager.this, "Refreshing request sent successfully for list of size : " + partitionModels.size());
}
}, (@NonNull Throwable throwable) -> {
Logger.get().d(ATTActionManager.this, "Error on Refresh request");
});
}
Run Code Online (Sandbox Code Playgroud)
问题 如果必须发送 2 个请求,有时我只会看到一个请求被发送。意思是,即使 for 循环为 2 个请求(HTTP)执行了两次,我看到只有一个请求被发送到服务器。我在这里做错了什么?正在使用的 Rxjava 版本:2.2.19
无法发出新请求,因为之前的响应仍处于打开状态:请在改造中调用 response.close()
APIService.userLogin(jobj).enqueue(new Callback<LoginRequest>(){
@Override
public void onResponse(Call<LoginRequest> call, Response<LoginRequest> response) {
System.out.println(("response ===" + response));
ApiService getUser1 = RetrofitRequest.getClient().create(ApiService.class);
final Profile profile = Profile.getInstance();
getUser1.getUser().enqueue(new Callback<GetUser>() {
@Override
public void onResponse(Call<GetUser> call, Response <GetUser> response) {
LoginRequest user = response.body();
ApiService getUser1 = RetrofitRequest.getClient().create(ApiService.class);
getUser1.getUser().enqueue(new Callback<GetUser>() {
@Override
public void onResponse(Call<GetUser> call, Response <GetUser> response) {
}
@Override
public void onFailure(Call<GetUser> call, Throwable t) {
System.out.println("GetUseronFailure" + t );
}
});
}
@Override
public void onFailure(Call< LoginRequest > call, …Run Code Online (Sandbox Code Playgroud) 我有一个ViewModel正在观察Observable我MainRepo班级中的 RxJava 。我试图让我WebsocketListener在MainRepo课堂上发出事件,但我不确定如何这样做。
MainRepo 类:
private WebSocket ws;
public void createWsConnection() {
Request request = new Request.Builder()
.url(Constants.WEBSOCKET_ENDPOINT)
.addHeader(Constants.WEBSOCKET_HEADERS_KEY, Constants.USER_ID)
.build();
OkHttpClient client = new OkHttpClient
.Builder()
.pingInterval(30, TimeUnit.SECONDS)
.build();
this.ws = client.newWebSocket(request, webSocketListener);
}
Run Code Online (Sandbox Code Playgroud)
这是我感到困惑的地方。我不知道如何将 websocket 与 RxJava observable 一起使用。
public Observable<String> createListener(){
return Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(@NonNull ObservableEmitter<String> emitter) {
//I don't know what to put here in order to emit messages
//back to my …Run Code Online (Sandbox Code Playgroud) android ×10
rx-java ×10
rx-java2 ×4
java ×3
crashlytics ×2
okhttp ×2
performance ×2
retrofit2 ×2
android-mvvm ×1
android-room ×1
firebase ×1
retrofit ×1
rx-java3 ×1
threadpool ×1