gpt4 book ai didi

android - 崩溃后开始 Activity

转载 作者:行者123 更新时间:2023-12-03 17:18:30 24 4
gpt4 key购买 nike

例如,我的应用程序抛出NullPointerException。如何打开 Activity (例如– SendCrashLogActivity或完成的Activity1)?
我的场景:enter image description here

您可以使用small demo application重现此方案

如果是不可能的,则不应重新启动应用程序。

Thread.setDefaultUncaughtExceptionHandler (new Thread.UncaughtExceptionHandler()
{
@Override
public void uncaughtException (Thread thread, Throwable e)
{
Intent intent = new Intent (getApplicationContext(),DrawView.class);
startActivity(intent); //after calling this method, my application will be frozen. Android 6
}
});

最佳答案

在startActivity(intent)之后使用以下代码

android.os.Process.killProcess(android.os.Process.myPid());
System.exit(10);

关于android - 崩溃后开始 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34356015/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com