Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MapActivity with StrictMode does not work - Help

After reading Tim Bray's post "New Gingerbread API: StrictMode" on the Android developer's blog, I decided to start using it on my projects. I'm hoping to help catch performance problems before they become problems.

My problem is that every time I try to load my MapActivity the app dies, but only when StrictMode is enabled. It dies even with a simple, no code activity.

Has anyone successfully used StrictMode with MapActivity? If so, what is the trick?

The output from LogCat is:

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}

The Activity code is: (I know there is extra stuff, but I wanted to see what standard methods were executing)

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;
    }

}

The layout is:

<?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>
like image 609
Carl G Avatar asked Jul 14 '11 21:07

Carl G


1 Answers

You are fine, AFAIK. MapView and MapActivity were written back in 2008 or so and have not been substantially modified since then, from what I can tell. I am not surprised that have some bad practices, such as I/O on the main application thread.

like image 170
CommonsWare Avatar answered Oct 24 '22 02:10

CommonsWare