Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Network plugin handleOnResume throws ANR

未关闭
#2,563 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
java

调研方向

从 network/android/src/main/java/com/capacitorjs/plugins/network/NetworkPlugin.java 中的 handleOnResume 开始,检查 Network.getNetworkStatus,尤其是 ANR trace 中显示的 ConnectivityManager 调用。在选择执行路径之前,检查此 plugin 或 repository 如何分派后台工作。完成的标准是,resume 处理不再阻塞主线程,同时保留网络状态行为。

由索引模型根据 Issue 内容生成。

描述

triage

The network plugin's handleOnResume calls getNetworkStatus from main thread, which can be a slow operation:
https://github.com/ionic-team/capacitor-plugins/blob/2be8127d580a847c832698169893079b3960b9f3/network/android/src/main/java/com/capacitorjs/plugins/network/NetworkPlugin.java#L60

I've seen a crashlytics report of an ANR thrown because of this:

android.os.BinderProxy.transactNative (Native method)
This Binder call may be taking too long, causing the main thread to wait, and triggering the ANR.
android.os.BinderProxy.transact (BinderProxy.java:659)
android.net.IConnectivityManager$Stub$Proxy.getActiveNetwork (IConnectivityManager.java:1798)
android.net.ConnectivityManager.getActiveNetwork (ConnectivityManager.java:1549)
com.capacitorjs.plugins.network.Network.getNetworkStatus (Network.java:77)
com.capacitorjs.plugins.network.NetworkPlugin.handleOnResume (NetworkPlugin.java:60)
com.getcapacitor.Bridge.onResume (Bridge.java:1347)
com.getcapacitor.BridgeActivity.onResume (BridgeActivity.java:98)
android.app.Instrumentation.callActivityOnResume (Instrumentation.java:1490)
android.app.Activity.performResume (Activity.java:8281)
android.app.ActivityThread.performResumeActivity (ActivityThread.java:4960)
android.app.ActivityThread.handleResumeActivity (ActivityThread.java:5018)
android.app.servertransaction.ResumeActivityItem.execute (ResumeActivityItem.java:60)
android.app.servertransaction.ActivityTransactionItem.execute (ActivityTransactionItem.java:45)
android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:176)
android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:97)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:2374)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loopOnce (Looper.java:233)
android.os.Looper.loop (Looper.java:344)
android.app.ActivityThread.main (ActivityThread.java:8249)
java.lang.reflect.Method.invoke (Native method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:589)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1071)

Perhaps this call should make from a background thread like this?

@Override
public void handleOnResume() {
    super.handleOnResume();
    
    // Dispatch heavy operations off the Main thread
    CapacitorJS.getEngine().executeOnBackgroundThread(() -> {
        // Your background work here
    });
}
``
主要语言
Java
星标
682
派生
689
平均合并
5 天 11 小时
30 天内合并 PR
3

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ionic-team/capacitor-plugins 的其他 Issue

查看 ionic-team/capacitor-plugins 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。