在Android開發者博客閱讀Tim Bray's post "New Gingerbread API: StrictMode"後,我決定開始使用它在我的項目。我希望在出現問題之前幫助解決性能問題。MapActivity與StrictMode不工作 - 幫助
我的問題是,每次我試圖加載我MapActivity應用死亡,但啓用StrictMode只有當。即使是一個簡單的,沒有代碼活動,它也會死亡。
有沒有人成功地使用StrictMode與MapActivity?如果是這樣,有什麼竅門?
從logcat的輸出是:
TestActivity - onCreate
TestActivity - onStart
TestActivity - onResume
Handling network change notification:CONNECTED
Couldn't get connection factory client
StrictMode policy violation; ~duration=344 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=343 violation=2
at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:745)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:330)
at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:280)
at com.google.android.gsf.settings.GoogleSettingsProvider.query(GoogleSettingsProvider.java:142)
at android.content.ContentProvider$Transport.bulkQuery(ContentProvider.java:174)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:111)
at android.os.Binder.execTransact(Binder.java:320)
at dalvik.system.NativeStart.run(Native Method)
# via Binder call with stack:
android.os.StrictMode$LogStackTrace
at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1059)
at android.os.Parcel.readExceptionCode(Parcel.java:1304)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:111)
at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:330)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
at android.content.ContentResolver.query(ContentResolver.java:262)
at android_maps_conflict_avoidance.com.google.common.android.AndroidConfig.getSetting(AndroidConfig.java:216)
at android_maps_conflict_avoidance.com.google.common.android.AndroidConfig.getDistributionChannelInternal(AndroidConfig.java:195)
at android_maps_conflict_avoidance.com.google.common.Config.init(Config.java:273)
at android_maps_conflict_avoidance.com.google.common.android.AndroidConfig.<init>(AndroidConfig.java:100)
at android_maps_conflict_avoidance.com.google.common.android.AndroidConfig.<init>(AndroidConfig.java:87)
at com.google.android.maps.MapActivity.onCreate(MapActivity.java:419)
at com.company.project.UI.TestActivity.onCreate(TestActivity.java:15)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:1487)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654)
at android.widget.TabHost.setCurrentTab(TabHost.java:326)
at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:132)
at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:456)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
StrictMode policy violation with POLICY_DEATH; shutting down.
Sending signal. PID: 1254 SIG: 9
Process com.company.project (pid 1254) has died.
channel '4073e288 com.company.project/com.company.project.UI.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x8
channel '4073e288 com.company.project/com.company.project.UI.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
WIN DEATH: Window{4073e288 com.company.project/com.company.project.UI.MainActivity paused=false}
活動代碼是:(我知道有多餘的東西,但我想看看有什麼標準方法執行)
public class TestActivity extends MapActivity {
private final static String TAG = "TestActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.d(TAG, "TestActivity - onCreate");
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.d(TAG, "TestActivity - onStart");
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.d(TAG, "TestActivity - onResume");
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.d(TAG, "TestActivity - onPause");
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.d(TAG, "TestActivity - onStop");
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
Log.d(TAG, "TestActivity - onRestart");
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.d(TAG, "TestActivity - onDestroy");
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
Log.d(TAG, "TestActivity - isRouteDisplayed");
return false;
}
}
佈局是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.maps.MapView
android:id="@+id/campusMap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="<key>" />
</LinearLayout>
:好像也許你'StrictMode'設置在當遇到主應用程序線程上I/O它做什麼方面過於激進。你能顯示你的'StrictMode'配置代碼嗎? – CommonsWare
我的原始代碼是: StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()。detectAll()。penaltyLog()。penaltyDeath()。build()); StrictMode.setVmPolicy(新StrictMode.VmPolicy.Builder()detectAll()penaltyLog()penaltyDeath()建立()。。); 但我將其更改爲: StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()。detectAll()。penaltyLog()。build()); StrictMode.VmPolicy.Builder()。detectAll()。penaltyLog()。build()); 去除.penaltyDeath() –
,做的是解決它? penaltyDeath()是最後的。 :-) – CommonsWare