简体   繁体   中英

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).

Sometimes, when the app should show a progress dialog followed by a Toast containing a message, it crashes instead; looking on Play Console, I see this stack trace:

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.

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.

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):

@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).

What could it be?


Edit 31/07/2020: add code snippets

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. Try Executing one after the other one is finished

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM