a previous question 광산과 관련하여 예외가 Thread.UncaughtExceptionListener
에 걸렸을 때 상황을 정확히 알고 싶습니다. 잡히지 않은 예외가 청취자에 의해 수신 될 때, 문맥은 림보 (limbo) 상태에 빠진 것처럼 보인다. 그것은 몇 가지 방법 (주로 자원에 관한 것)에 접근 할 수 있지만, 많은 사람들이 작동하지 않는다 (또는 눈에 보이지 않게 작동한다). 새로운 활동의 스레드가 UncaughtException을 catch하기 전에 컨텍스트에 어떤 일이 발생합니까
Toast
(내 링크 등)Dialog
- 창조 :이 (좀 더 내가 발견하지 않았습니다가 확신하며 이에 제한되지 않음)이 포함되어 있습니다. 여기에는 보통
Context.startActivity(Intent)
및PendingIntent
이 포함됩니다. 상황은 여전히 문맥 자원 (getString()
,Resources
하고 이상하게Notification
들)에게 자명 액세스 할 수 있습니다 그러나
.
왜인가요? 문맥 기반 호출을 방지하기 위해 컨텍스트에서이 상태 불균형 (?)이 발생하는 이유는 무엇입니까?
아래 예외가 잡히지 않은 상태에서 오류 활동을 시작한다고 가정하는 테스트 응용 프로그램을 작성했습니다. 내가하고있는 상황에서 내가 언급 한 (토스트와 대화) 것을 테스트하기 위해 빌더를 알림 빌더 대신 BoomMitActivity에 배치하십시오.
주어진 예제에서 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);
}
}
}
매니페스트 :
<?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>
왜 '정적'으로'BoomMitActivity'를 얻었습니까? – Ronnie
@ userSeven7s 중첩 된 활동을 정적으로 선언 할 수 없습니다. 나는 그것을 자신의 클래스에 쉽게 배치 할 수 있었지만 테스트를 위해 AndroidTestoActivity에서 테스트하는 것이 더 쉬웠다. – AedonEtLIRA
일반 수업과도 같습니까? – Ronnie