0

I've read a lot of articles but none of them could fix my problem of not calling the onCreate-method in the class XMLParsingExample.

The log-statement in the onCreate didn't show output and tracing shows that the class is exited after boolean finished=false and thus not running the onCreate.

Here the codes:

public class MyMap extends MapActivity {

private MapView mapView;
private MapController mc;
private OverlayItem overlayItem;
private List<Overlay> mapOverlays;
private Drawable drawable;
private Drawable drawable2;
private MyItemizedOverlay itemizedOverlayMyLoc;
private MyItemizedOverlay itemizedOverlayRust;
private LocationManager locMgr;
private MyLocationListener locLstnr;XMLParsingExample mXMLParsingExample;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);

        mc = mapView.getController();
        mapView.setBuiltInZoomControls(true);

        locMgr = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        locLstnr = new MyLocationListener();
        locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locLstnr);

        mapOverlays = mapView.getOverlays();

        // first overlay
        drawable = getResources().getDrawable(R.drawable.marker2);
        itemizedOverlayMyLoc = new MyItemizedOverlay(drawable, mapView);

        //                                  LAT                 LONG
        GeoPoint uwLoc = new GeoPoint((int)(52.22778*1E6),(int)(6.10428*1E6));
        overlayItem = new OverlayItem(uwLoc, "Uw locatie", "http://www.nu.nl");
        itemizedOverlayMyLoc.addOverlay(overlayItem);
        mapOverlays.add(itemizedOverlayMyLoc);

        // Rustpunten overlay
        drawable2 = getResources().getDrawable(R.drawable.rmarker3);
        itemizedOverlayRust = new MyItemizedOverlay(drawable2, mapView);

        mXMLParsingExample = new XMLParsingExample();

and here the class which where the oncreate isn't called:

public class XMLParsingExample extends Activity {

/** Create Object For SiteList Class */
public SitesList sitesList = null;
public ProgressDialog progressDialog;
boolean finished=false;

    /** Called when the activity is first created. */
    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Log.i("onCreate", "onCreate started");
}
Qwyrp
  • 147
  • 1
  • 1
  • 11

2 Answers2

4

Starting a new Activity is not done by instantiating it (new XMLParsingExample();), but with an intent, for example:

Intent intent = new Intent(this, XMLParsingExample.class);
startActivity(intent);

Take a look at the here.

MByD
  • 135,866
  • 28
  • 264
  • 277
0

Binyamin Sharet is correct.

I think you are confusing a creator method, which does get called when you allocate an object, and onCreate(), which is an Android lifecycle callback function that gets called automatically by the framework at the appropriate time.

A creator function doesn't usually have 'create' in its name; it shares the name of the class whose object you are instantiating. In your case, the creator would be called XMLParsingExample().

For more information about Android lifecycle callbacks, see http://developer.android.com/guide/topics/fundamentals/activities.html.

Sparky
  • 8,437
  • 1
  • 29
  • 41