在Android开发者博客上阅读Tim Bray's post "New Gingerbread API: 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>
答案 0 :(得分:6)
你很好,AFAIK。 MapView
和MapActivity
是在2008年左右写回来的,从那时起我就没有经过实质性的修改。有一些不好的做法,例如主应用程序线程上的I / O,我并不感到惊讶。