Sketchware-Pro icon indicating copy to clipboard operation
Sketchware-Pro copied to clipboard

When App Crashes, Debug Screen no longer shows with error

Open RoyTheReal opened this issue 1 year ago • 12 comments

If my app crashes, Debug activity doesn't come up anymore so I don't know what the error message is. And I can't use logcat because I don't have root.

RoyTheReal avatar May 30 '24 00:05 RoyTheReal

FYI: You can use a logcat reader without root access or a computer if you're on Android 11 or higher. Try one of those logcat apps on Google Play, or use Shizuku and Termux to access the system binary directly.

j-px avatar May 30 '24 06:05 j-px

Okay I check it out. Why doesn't the DebugActivity show anymore when there's a crash though? Can it be fixed?

RoyTheReal avatar May 30 '24 11:05 RoyTheReal

It was never there by default. You can create a new activity with that name then It'll be called automatically when a crash happens.

ilyassesalama avatar May 30 '24 12:05 ilyassesalama

Well back in the past I specifically remember it would always show the crash log after a crash. It just doesn't do that anymore.

On Thu, May 30, 2024, 8:30 AM Ilyasse @.***> wrote:

It was never there by default. You can create a new activity with that name then It'll be called automatically when a crash happens.

— Reply to this email directly, view it on GitHub https://github.com/Sketchware-Pro/Sketchware-Pro/issues/1140#issuecomment-2139451341, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ3NVF4QDCQZQHADAVI53PDZE4LVNAVCNFSM6AAAAABIP4MX3OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZZGQ2TCMZUGE . You are receiving this because you authored the thread.Message ID: @.***>

RoyTheReal avatar May 30 '24 12:05 RoyTheReal

It used to show a dialog with the full crash log that you could then copy, but now when an app crashes, it just shows a blank screen.

RoyTheReal avatar May 30 '24 13:05 RoyTheReal

Whenever apps don't show the stack trace like that, going to the home screen, opening Recents, opening the app again from there, and combos of that often help, at least for me. Maybe try that.

This seems hard to fix, and the issue of the dialog not showing has been there forever. Newer Android versions probably introduced limits which made the chance of that happening much higher.

j-px avatar May 30 '24 14:05 j-px

Whenever apps don't show the stack trace like that, going to the home screen, opening Recents, opening the app again from there, and combos of that often help, at least for me. Maybe try that.

This seems hard to fix, and the issue of the dialog not showing has been there forever. Newer Android versions probably introduced limits which made the chance of that happening much higher.

Yeah, that's what I started doing months back but now that I updated to Android 14, the error message rarely shows up. It's like a 5% chance that I'll get to see the error message. Most of the time, the app will just freeze up or crash now without any error message. There has to be some way to fix it. Error messages used to be extremely helpful.

RoyTheReal avatar May 30 '24 16:05 RoyTheReal

You can't just copy-paste code freely while ignoring the license.

j-px avatar May 31 '24 07:05 j-px

Maybe it's time we update/fix the default crash handler. This code below works for my app every time, I'll try to port it to SKPro if I get an upvote (from mods)

class ApplicationClass : Application() {
    override fun onCreate() {
        super.onCreate()
        Thread.setDefaultUncaughtExceptionHandler { _: Thread?, throwable: Throwable? ->
            val intent = Intent(applicationContext, MainActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
            intent.putExtra("stacktrace", Log.getStackTraceString(throwable))
            startActivity(intent)
            Process.killProcess(Process.myPid())
            exitProcess(1)
        }
    }
}

In MainActivity

//Any crash logs sent via DefaultUncaughtExceptionHandler
        intent.getStringExtra("stacktrace")?.let { eventLog("Application Crashed", it) }

        LocalBroadcastManager.getInstance(this).registerReceiver(
            eventLogBroadcastReceiver,
            IntentFilter("eventLog")
        )

khaled-0 avatar May 31 '24 17:05 khaled-0

Maybe it's time we update/fix the default crash handler. This code below works for my app every time, I'll try to port it to SKPro if I get an upvote

class ApplicationClass : Application() {
    override fun onCreate() {
        super.onCreate()
        Thread.setDefaultUncaughtExceptionHandler { _: Thread?, throwable: Throwable? ->
            val intent = Intent(applicationContext, MainActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
            intent.putExtra("stacktrace", Log.getStackTraceString(throwable))
            startActivity(intent)
            Process.killProcess(Process.myPid())
            exitProcess(1)
        }
    }
}

In MainActivity

//Any crash logs sent via DefaultUncaughtExceptionHandler
        intent.getStringExtra("stacktrace")?.let { eventLog("Application Crashed", it) }

        LocalBroadcastManager.getInstance(this).registerReceiver(
            eventLogBroadcastReceiver,
            IntentFilter("eventLog")
        )

Yes fix it! Do it!

RoyTheReal avatar May 31 '24 17:05 RoyTheReal

@guhg Please test with https://github.com/Sketchware-Pro/Sketchware-Pro/actions/runs/9328652398

khaled-0 avatar Jun 01 '24 07:06 khaled-0

@guhg Please test with https://github.com/Sketchware-Pro/Sketchware-Pro/actions/runs/9328652398

I tried it! Works wonders!

RoyTheReal avatar Jun 01 '24 12:06 RoyTheReal