Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E/CustomActivityOnCrash: App has crashed, executing CustomActivityOnCrash's UncaughtExceptionHandler #44

Closed
utkarshGithub opened this issue Oct 23, 2017 · 8 comments
Milestone

Comments

@utkarshGithub
Copy link

I am using custom error activity , below is my manifest file

<activity
           android:name="com.o1.shop.ui.activity.CustomErrorActivity"
           android:process=":error_activity"
           android:screenOrientation="portrait">
           <intent-filter>
               <action android:name="cat.ereza.customactivityoncrash.ERROR"/>
           </intent-filter>
       </activity>

and this my application file

CleverTapAPI.changeCredentials(DeviceUtils.getCleverTapAccountID(BuildConfig.FLAVOR), DeviceUtils.getCleverTapAccountToken(BuildConfig.FLAVOR));
        ActivityLifecycleCallback.register(this);
        super.onCreate();
        CaocConfig.Builder.create()
                .enabled(true)
                .minTimeBetweenCrashesMs(2000) //default: 3000
                .errorActivity(CustomErrorActivity.class) //default: null (default error activity)
                .apply();

i cannot see the custom crash activity

@Ereza
Copy link
Owner

Ereza commented Nov 13, 2017

Hi @utkarshGithub, sorry for taking a while to reply. Did you manage to solve the problem?

Your code appears to be fine (however, if you set the errorActivity via CaocConfig, the intent-filter is not really needed). Could you provide a minimal project so I can check if there is any other issue that causes this?

Thanks!

@alaegin
Copy link

alaegin commented Jan 19, 2018

The same issue.

Some details:

Tested on OnePlus 5 with 7.1 android and HTC One S on 4.1.
Caoc ver. 2.2.0

compileSdkVersion 26
buildToolsVersion '26.0.2'
...
targetSdkVersion 26
...
compile 'cat.ereza:customactivityoncrash:2.2.0'
compile 'com.google.firebase:firebase-core:11.8.0'
compile('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
    transitive = true
}

Config in application class:

        CaocConfig.Builder.create()
                .backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT) 
                .logErrorOnRestart(true)
                .errorActivity(CrashActivity.class)
                .apply();

CrashActivity.class is my custom activity which works absolutely 100%.

The issue takes part if I call throw new RuntimeException(); at the end of activitie's onCreate method - there will be nothing. If I call it from onDestroy/onResume etc. it will work right.

Also, if I use throw with some delay it will work!


        // At the end of onCreate in first activity
        new Handler().postDelayed(new Runnable() {
            @Override public void run() {

            }
        }, 500);

It seems as if it does not have time to start. If I call any exception after some delay from initialization - it will work fine. Also, it will work fine in any onCreate methods in future activities.

@Ereza
Copy link
Owner

Ereza commented Jan 19, 2018

Hi @DominuS-RU, can you provide a minimal project with all the code so I can reproduce the issue? I'm assuming that the problem doesn't happen on the sample project, can you check?

Thanks!!

@alaegin
Copy link

alaegin commented Jan 19, 2018

@Ereza Hello!
I've updated my previous comment with some details.
I'll test sample project and will try to give you test one in some hours.

Hope, my current details will help you.

@Ereza
Copy link
Owner

Ereza commented Jan 19, 2018

Thanks, I'll take a look into it!

@alaegin
Copy link

alaegin commented Jan 19, 2018

@Ereza, I've found the mistake.
It's the config for your sample:

CaocConfig.Builder.create()
.backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT)
.apply();

An exception for MainActivity
throw new RuntimeException("boom");

studio64_2018-01-19_16-58-20

Then, start you application and see nothing.
The main issue in .backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT), if we delete this one the library will work fine. All behavior is repeated as I've described in my first comment.

@alaegin
Copy link

alaegin commented Feb 3, 2018

Anything new about this issue?

@Ereza
Copy link
Owner

Ereza commented Feb 19, 2020

Hi, sorry for the ultralate reply.

With the examples you provided, I saw that there was an issue when the background mode is "silent" and the app is being launched. The background/foreground detection mechanism relies on started activities, and obviously a new activity that crashes in onCreate is not started yet, so the library thinks that the app is in background and does not show the error activity.

I solved this by recording the last time an activity was created (onActivityCreated is called before onCreate ends). If the activity crashes while in "background" but the last activity creation was less than 500 ms ago, the app is assumed to be in foreground and the activity is shown.

This will be available in the next release of the library.

@Ereza Ereza closed this as completed in 19de722 Feb 19, 2020
@Ereza Ereza added this to the 2.3.0 milestone Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants