14

When my app is in the process of resuming, it crashes inside Android framework code . I am unable to reproduce the crash and am only aware of it through crash reporting. Furthermore, the crash occurs on Android 7, 8, 9 and is spread among many manufacturers.

Here is the stacktrace for the android.os.RemoteException which causes the crash:

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)

The above exception was triggered by my Activity's super.onResume() call which then raised an IllegalArgumentException at android.os.Parcel.createException + 1970 (Parcel.java:1970) androidx.fragment.app.FragmentActivity.onResume + 514 (FragmentActivity.java:514)

Finally, the above exception was caught as a RuntimeException since the system was unable to start the app. Here's the last stacktrace:

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

No code is ran inside my onResume functions besides a call to super.

I tried backgrounding/foregrounding the app in the offending Activity while limiting background processes and "Don't keep Activities" turned on, but I could not reproduce the crash.

Does anyone have suggestions for reproducing the crash?

Here is code showing how the Service is started:

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

Here is code shutting down the 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
}
clever_trevor
  • 1,530
  • 2
  • 22
  • 42
  • Is your `Activity` binded with any service? – Deˣ Jun 25 '19 at 15:19
  • @derek no it is not. It does communicate with a service which is bound to the application. – clever_trevor Jun 25 '19 at 17:13
  • From where are you starting the `Service`? Post the code. Is it in `Activity` or `Application`? Also, share the base skeleton of your `Service` class. – Deˣ Jun 25 '19 at 17:22
  • Recent Android versions doesn't allow the `Service` class to start from BackGround. This can also be a cause. I somehow suspect this is related to your `Service` class and the way you have binded it. – Deˣ Jun 25 '19 at 17:25
  • I added code showing the `Application` context starting the `Service`. I checked the context starting it was not an instance of any `Activity` at runtime to be sure. There is no call to `bindService` anywhere – clever_trevor Jun 25 '19 at 18:17
  • Hi @clever_trevor did you find any fix to this crash or the cause of this crash ? – shadygoneinsane May 09 '20 at 04:46
  • @shadygoneinsane nope – clever_trevor May 12 '20 at 16:03
  • See the answers to this question: https://stackoverflow.com/q/3156389/495319 – Wodin Oct 31 '20 at 06:32

0 Answers0