- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
结合a previous question我的,我想知道当异常被 Thread.UncaughtExceptionListener
捕获时,上下文到底发生了什么。当监听器接收到未捕获的异常时,上下文似乎陷入了困境。它可以访问它的一些方法(主要是与资源有关的方法),但是很多方法不起作用(或明显不起作用)。这包括(但不限于,我确定还有更多我没有找到):
Toast
(如我的链接)对话框
Context.startActivity(Intent)
和 PendingIntent
。然而,上下文仍然可以访问上下文资源(getString()
、Resources
和奇怪的 Notification
)。
这是为什么?是什么导致上下文中的这种状态不平衡(?)阻止任何上下文驱动的调用?
下面我为您创建了一个测试应用程序,假设在未捕获异常时启动错误 Activity 。要在我一直在做的情况下测试我提到的事情( toast 和对话),将它们的构建器放在 BoomMitActivity 中代替通知构建器。
在给定的示例中, Activity 出错(怎么可能不出错?)并在单击 Notification
时启动 BoomMitActivtiy。但是,从未调用 BoomMit 的 onCreate
。
应用:
public class AndroidTestoActivity extends Activity implements UncaughtExceptionHandler {
@Override public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Thread.setDefaultUncaughtExceptionHandler(this);
throw new RuntimeException("HAHAHAHA, I broke you");
}
@Override public void uncaughtException(Thread arg0, Throwable arg1) {
finish();
NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.ic_launcher, "Boom!", System.currentTimeMillis());
Intent i = new Intent(this, BoomMitActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi = PendingIntent.getActivity(this, 1, i, PendingIntent.FLAG_ONE_SHOT);
note.setLatestEventInfo(this, "Boom!", "Open BoomMitActivity", pi);
note.flags |= Notification.FLAG_AUTO_CANCEL;
nm.notify(1, note);
Log.d("TAG", "End");
}
static class BoomMitActivity extends Activity {
@Override public void onCreate(Bundle icicle) {
super.onCreate(icicle);
TextView tv = new TextView(this);
tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
tv.setBackgroundColor(0xffff0000);
tv.setText("BoomMitActivity is the one true activity");
tv.setTextColor(0xff00ffff);
setContentView(tv);
}
}
}
list :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.testo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".AndroidTestoActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="AndroidTestoActivity$BoomMitActivity"
android:label="I'm a real boy!"
android:taskAffinity=""
android:excludeFromRecents="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
最佳答案
Context 本身没有任何变化。如果你说的是当你处于应用程序崩溃对话框出现的情况时,那么崩溃的线程就坐在那里等待用户按下一个按钮并让它继续自杀。此时系统知道你的应用程序已被删除,只是等待用户确认并最终终止它。所以你真的应该假设你正在出路,而不是依赖任何有效的东西。
此外,如果这次崩溃来自主线程,那么该线程现在正处于阻塞状态,等待用户确认崩溃对话框,以便它可以自杀。它不是坐在那里处理它的消息循环,而是坐在那里完全阻塞等待自杀。不会执行计划在该线程上的任何工作。对于主线程,这包括对 Activity.onCreate()、Service.onStart() 等组件的回调。对于任何线程,这包括为与该线程关联的窗口 UI 分派(dispatch)任何工作。同样,如果这是主线程,这可能意味着您的所有 UI。
关于android - 在 Thread 捕获 UncaughtException 之前上下文会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10485001/
出现以下错误 Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable D
在调试应用程序时出现以下错误。 The CLR has been unable to transition from COM context 0x3b2d70 to COM context 0x3b2
在 GAE Go 中,为了记录,我们需要使用 appengine.NewContext(r) 创建一个新的上下文,它返回 context.Context。 如何使用此上下文在请求范围内设置/获取变量?
我想使用 Puppeteer 从放置在页面上 iframe 内的选择器中获取数据,该页面在与其父框架域不同的域上运行。因此,我不是任何域的所有者 - 无法使用 frame.postMessage。 试
我正在尝试获取可用的应用程序上下文并想切换到 webview 上下文,但 appium 仅获取 Navive App。 应用程序还启用了 WebView。 Appium 版本:1.10.1 Chrom
这个问题在这里已经有了答案: How to fix this nullOk error when using the flutter_svg package? (7 个回答) 7 个月前关闭。 当我尝
我观看了关于 Core Data 的 2016 WWDC 视频并查看了各种教程。我见过使用 Core Data Framework 创建对象以持久保存到 managedObjectContext 中的
这是代码 obj = { a: 'some value'; m: function(){ alert(this.a); } } obj.m(); 结果是'som
我正在尝试做类似的事情 $(".className").click(function() { $(this).(".anotherClass").css("z-index","1");
var User = { Name: "Some Name", Age: 26, Show: function() { alert("Age= "+this.Age)}; }; fun
我目前正在使用我见过的常见 Context 模式,它允许子组件通过传递修饰函数来更新父组件的状态(即 Provider)通过共享的 Context。 我遇到的问题是,修改函数只引用原始状态,不引用最新
有没有办法让 React Context类型安全与流类型? 例如: Button.contextTypes = { color: React.PropTypes.string }; 最佳答案 不幸
我想知道是否有一种方法可以为不同的功能使用不同的上下文类。 我希望有一个功能使用 MinkExtensions 进行浏览器测试,另一个功能使用和 HTTP 客户端(如 Guzzle)进行 API 测试
我有这个配置文件 apiVersion: v1 clusters: - cluster: server: [REDACTED] // IP of my cluster name: stag
我在实现非抢先式调度时遇到了用于初始化TCB的代码。 typedef struct TCB_t { struct TCB_t *next; struct TCB_t
我想将一个函数设置为数组中每个元素的属性,但使用不同的参数调用它。我想我会使用匿名函数来解决它: for ( var i = 0; i < object_count; i++ ) { obje
这个问题已经有答案了: How to access the correct `this` inside a callback (15 个回答) 已关闭 7 年前。 我正在做一些练习,但我在管道方法中丢
我正在尝试通过 Java 和 Android Studio 学习和制作 Android 应用程序。我对Java的了解程度是两年前几个小时的youtube学习和大学基础类(class)。不过我确实知道如
我在(这个)上遇到了问题。错误ImageView无法应用。我在 fragment 类中执行此代码。 ViewFlipper v_flipper; @Nullable @Override public
我想使用 openGL 的某些功能,但与渲染视觉内容无关。有没有办法在没有任何依赖性的情况下创建它(不是对 Windows,也不是某些包[SDL,SFML,GLUT])?只允许使用没有外部库的库,就像
我是一名优秀的程序员,十分优秀!