首页 > 解决方案 > 恢复时我的应用程序因 RemoteException 而崩溃

问题描述

当我的应用程序处于恢复过程中时,它会在 Android 框架代码中崩溃。我无法重现崩溃,只能通过崩溃报告知道它。此外,崩溃发生在 Android 7、8、9 上,并且在许多制造商之间传播。

这是android.os.RemoteException导致崩溃的堆栈跟踪:

com.android.server.am.ActivityManagerService.isTopOfTask(ActivityManagerService.java:14764) at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2417) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3346) at android.os.Binder.execTransact(Binder.java:731)

上面的异常是由我Activitysuper.onResume()调用触发的,然后引发了IllegalArgumentExceptionat android.os.Parcel.createException + 1970 (Parcel.java:1970) androidx.fragment.app.FragmentActivity.onResume + 514 (FragmentActivity.java:514)

RuntimeException最后,由于系统无法启动应用程序,因此捕获了上述异常。这是最后一个堆栈跟踪:

android.app.ActivityThread.performResumeActivity + 4015 (ActivityThread.java:4015) com.android.internal.os.ZygoteInit.main + 965 (ZygoteInit.java:965)

除了onResume调用super.

Activity我在限制后台进程和“不要保持活动”打开的同时尝试在违规中将应用程序后台/前台,但我无法重现崩溃。

有没有人有重现崩溃的建议?

这是显示如何Service启动的代码:

@Singleton
class ExoplayerManager @Inject constructor(
        @Application private val context: Context,
        ...
) : CastManager.CastEventListener {

    private fun startService() {
        lecture?.let {
            val intent = ExoplayerService.createIntent(context, it.generateCompositeIdObject())

            logd { "[ExoplayerService] startForegroundService called" }
            ContextCompat.startForegroundService(context, intent)
        }
    }
}

这是关闭的代码Service

public class ExoplayerService extends Service {

    public static Intent createIntent(Context context, LectureCompositeId id) {
        Intent intent = new Intent(context, ExoplayerService.class);
        intent.putExtra(EXTRA_LECTURE_COMPOSITE_ID, (Parcelable) id);
        return intent;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        String action = null;
        LectureCompositeId lectureCompositeId = null;
        if (intent != null) {
            action = intent.getAction();
            lectureCompositeId = intent.getParcelableExtra(EXTRA_LECTURE_COMPOSITE_ID);
        }

        L.leaveBreadcrumb(TAG, "onStartCommand >> startId: " + startId + " flags: " + flags +
                " intent: " + intent + "action: " + action + " lectureCompositeId: " + lectureCompositeId);

        // Actions are send by Notification and lock screen controls as intent params
        if (intent != null) {
            if (ACTION_SHUTDOWN.equals(action) || ACTION_SHUTDOWN_TASK.equals(action)) {
                boolean fromNotification = intent.getBooleanExtra(EXTRA_SOURCE_NOTIFICATION, false);
                attemptShutdown(startId, fromNotification, ACTION_SHUTDOWN_TASK.equals(action));
            } else if (StringUtils.isNotBlank(action)) {
                exoplayerManager.ensureLecture(lectureCompositeId);
                handleNotificationMediaButtonAction(action);
            } else {
                initPlayerService();
            }
        }
        return START_STICKY;
    }

    /**
     * Queue a shutdown of the service.  Ensures requests that need a notification have a chance to process.
     */
    private void queueShutdown(boolean taskRemoved) {
        Intent shutdown = new Intent(this, ExoplayerService.class);


        if (taskRemoved) {
            shutdown.setAction(ACTION_SHUTDOWN_TASK);
        } else {
            shutdown.setAction(ACTION_SHUTDOWN);
        }

        startService(shutdown);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
// other methods
}

标签: android

解决方案


推荐阅读