gurujain / osmbonuspack

Automatically exported from code.google.com/p/osmbonuspack
0 stars 0 forks source link

Android 4.0.3 #9

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Follow Tutorial 1
2. Section "Hello, Routing World!" contains statement:
   Road road = roadManager.getRoad(waypoints); 
   which causes application to crash

What is the expected output? What do you see instead?
Drawing a route between two points. 

What version of the product are you using?
Android 4.0.3 HTC Sense 3.6 Application crash
Android 4.0.3 emulator Application crash
Android 2.2 Application works

Original issue reported on code.google.com by n3d...@gmail.com on 1 Sep 2012 at 6:32

GoogleCodeExporter commented 8 years ago
Emulator reports following error:

java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.test/com.test.MainActivity}: 
android.os.NetworkOnMainThreadException

Original comment by n3d...@gmail.com on 1 Sep 2012 at 6:34

GoogleCodeExporter commented 8 years ago
I just tried the Demo application with an Android 4.0.3 AVD
=> no crash, the app loads and display the road exactly as on previous Android 
versions!

Very strange. 

Could you download and try the OSMBonusPackDemo app on your emulator?

Could you tell which osmdroid and osmbonuspack versions you use?

And could you provide your source code?

Thanks

Original comment by mathieu....@gmail.com on 1 Sep 2012 at 8:50

GoogleCodeExporter commented 8 years ago
osmdroid 3.0.8
osmbonuspack 2.1

Code:

package com.test.android;

import java.util.ArrayList;

import org.osmdroid.bonuspack.routing.OSRMRoadManager;
import org.osmdroid.bonuspack.routing.Road;
import org.osmdroid.bonuspack.routing.RoadManager;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.PathOverlay;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {
        private MapView map;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        map = (MapView) findViewById(R.id.mapview);
        map.setTileSource(TileSourceFactory.MAPNIK);
        GeoPoint startPoint = new GeoPoint(48.13, -1.63);
        MapController mapController = map.getController();
        mapController.setCenter(startPoint);
        mapController.setZoom(15);

        RoadManager roadManager = new OSRMRoadManager();
        ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
        waypoints.add(startPoint);
        waypoints.add(new GeoPoint(48.4, -1.9)); //end point

        Road road = roadManager.getRoad(waypoints);

        PathOverlay roadOverlay = RoadManager.buildRoadOverlay(road, map.getContext());
        map.getOverlays().add(roadOverlay);
        map.invalidate();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

Original comment by n3d...@gmail.com on 1 Sep 2012 at 10:54

GoogleCodeExporter commented 8 years ago
Here is eclipse project:

http://ubuntuone.com/0KlvVfV2tQaVXBiPZTEb4S

Original comment by n3d...@gmail.com on 2 Sep 2012 at 5:08

GoogleCodeExporter commented 8 years ago
I found. Look at: 
http://developer.android.com/reference/android/os/NetworkOnMainThreadException.h
tml

Basically, from SDK 3.0, we can't do network calls in the main thread. 

I didn't got the issue on OSMBonusPackDemo because 1/ It targets an earlier SDK 
version, and 2/ all network calls in the demo are done in threads (async 
tasks). 

You have 2 solutions: 
- Give to your project a target SDK version earlier than 3.0 (even if the 
emulator or phone used is > 3.0)
- Do the calls in threads => looking at the source code of the demo app could 
help you. 

I will add a note about that issue in the tutorials. 

Original comment by mathieu....@gmail.com on 2 Sep 2012 at 7:26

GoogleCodeExporter commented 8 years ago
Thank you for response 

Original comment by n3d...@gmail.com on 2 Sep 2012 at 7:38

GoogleCodeExporter commented 8 years ago

Original comment by mathieu....@gmail.com on 5 Sep 2012 at 7:23