简体   繁体   English

应用程序代码外的 Android RuntimeException

[英]Android RuntimeException outside app code

I'm having a strange problem which is present only on a specific device (or at least is not present in the ~10 other devices I tested my app on).我遇到了一个奇怪的问题,它只存在于特定设备上(或者至少在我测试我的应用程序的大约 10 台其他设备上不存在)。

Sometimes, when the app should show a progress dialog followed by a Toast containing a message, it crashes instead;有时,当应用程序应该显示一个进度对话框,然后是一个包含消息的 Toast 时,它反而会崩溃; looking on Play Console, I see this stack trace:在 Play Console 上查看,我看到了这个堆栈跟踪:

java.lang.RuntimeException: 
  at android.view.InputChannel.nativeReadFromParcel (Native Method)
  at android.view.InputChannel.readFromParcel (InputChannel.java:148)
  at android.view.IWindowSession$Stub$Proxy.addToDisplay (IWindowSession.java:796)
  at android.view.ViewRootImpl.setView (ViewRootImpl.java:750)
  at android.view.WindowManagerGlobal.addView (WindowManagerGlobal.java:298)
  at android.view.WindowManagerImpl.addView (WindowManagerImpl.java:91)
  at android.widget.Toast$TN.handleShow (Toast.java:732)
  at android.widget.Toast$TN$1.run (Toast.java:631)
  at android.os.Handler.handleCallback (Handler.java:739)
  at android.os.Handler.dispatchMessage (Handler.java:95)
  at android.os.Looper.loop (Looper.java:145)
  at android.app.ActivityThread.main (ActivityThread.java:6939)
  at java.lang.reflect.Method.invoke (Native Method)
  at java.lang.reflect.Method.invoke (Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1404)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1199)

The progress bar and the Toast should be shown about once every 5 seconds.进度条和 Toast 应该大约每 5 秒显示一次。

As you can see, everything happens inside Android itself (there is no reference to my actual code), but I believe the following are the involved pieces of code.如您所见,一切都发生在 Android 本身内部(没有参考我的实际代码),但我相信以下是涉及的代码片段。

This is where the progress bar is shown:这是显示进度条的地方:

public abstract class FragmentNetworkingBenderAsyncTask<I, O> extends BenderAsyncTask<I, O> {

    @SuppressLint("StaticFieldLeak")
    private final Fragment fragment;
    private AlertDialog waitDialog;

    public FragmentNetworkingBenderAsyncTask(final Fragment fragment) {
        this.fragment = fragment;
    }

    @Override
    protected final void onPreExecute() {
        super.onPreExecute();
        if (fragment.isAdded()) {
            waitDialog = new SpotsDialog.Builder().setContext(fragment.getActivity()).build();           waitDialog.setMessage(MainActivity.commonContext.getString(R.string.Wait));
            waitDialog.show();
            innerOnPreExecute(); //abstract method
        } else {
            this.cancel(true);
        }
    }

    [...]

    @Override
    protected final void onPostExecute(final BenderAsyncTaskResult<O> result) {
        super.onPostExecute(result);
        if (fragment.isAdded()) {
            if (result.isSuccess()) {
                innerOnSuccessfulPostExecute(result); //abstract
            } else {
                innerOnUnsuccessfulPostExecute(result); //abstract
            }
        }
        waitDialog.hide();
    }
}

While this is where the Toast is shown (the class inherits from the one in the previous snippet):虽然这是显示 Toast 的地方(class 继承自上一个片段中的那个):

@SuppressLint("StaticFieldLeak")
private class ServerOrdersUploader extends FragmentNetworkingBenderAsyncTask<Order, Empty> {
    ServerOrdersUploader(Fragment fragment) {
        super(fragment);
    }

    [...]

    @Override
    protected void innerOnSuccessfulPostExecute(BenderAsyncTaskResult<Empty> result) {
        Toast.makeText(MainActivity.commonContext, MainActivity.commonContext.getString(R.string.UpdateSuccess), Toast.LENGTH_SHORT).show();
        new ServerOrdersDownloader(TableFragment.this).execute(tableNumber); //ServerOrdersDownloader has a similar behaviour
    }

    [...]
}
    

(full code is available here ) 此处提供完整代码)

As I said, the problem seems to happen only on a specific device (a Samsung Galaxy Tab A6 with Android 5.1).正如我所说,问题似乎只发生在特定设备上(带有 Android 5.1 的三星 Galaxy Tab A6)。

What could it be?会是什么呢?


Edit 31/07/2020: add code snippets编辑 31/07/2020:添加代码片段

It might be a bug with the OS itself as @Ben P. said, I feel the cause of the issue is when both progress bar and toast are sort of overlapped and the OS is buggy to handle it.正如@Ben P. 所说,这可能是操作系统本身的一个错误,我觉得问题的原因是进度条和吐司有点重叠并且操作系统处理它时有问题。 Try Executing one after the other one is finished尝试在另一个完成后执行一个

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Parcelable:RuntimeException:解组未知类型代码 - Android Parcelable: RuntimeException: Unmarshalling unknown type code Android 应用程序 java.lang.RuntimeException 错误 - Android app java.lang.RuntimeException error 为什么Android应用程序会在runtimeException之后自动重启? - why Android App auto restart after runtimeException? Android:java.lang.RuntimeException:在 android.app.ActivityThread.installProvider - Android: java.lang.RuntimeException: at android.app.ActivityThread.installProvider 运行时异常 - 由:android.database.sqlite.SQLiteException:没有这样的表:tbl(代码 1) - RuntimeException - Caused by: android.database.sqlite.SQLiteException: no such table: tbl (code 1) java.lang.RuntimeException:存根? - Android 代码覆盖率? - java.lang.RuntimeException: Stub! - Android Code Coverage? 带有parse.com推送通知的android应用上的RuntimeException - RuntimeException on android app with parse.com push notification Android Kotlin - MainActivity.I 中的应用程序崩溃 RuntimeException NullPointerException - Android Kotlin - app crash RuntimeException NullPointerException in MainActivity.I 异常:java.lang.RuntimeException 在 android.app.ActivityThread.handleReceiver - Exception : java.lang.RuntimeException at android.app.ActivityThread.handleReceiver Android - java.lang.RuntimeException:应用程序一启动就崩溃了 - Android - java.lang.RuntimeException:App is crashing as soon as it launches
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM