Android: wrong arguments on intent

I've got problems with using the Intent object of Android.

I'm basically trying to launch another activity:

My Activity, MapActivity, makes use of a MapEventListener, which provides functions to listen to events based on a map which is rendered in the MapActivty Activity. If a marker is pressed on the map, a function of the MapEventListener is Launched.

I this function I'm trying to implement an Intent object which launches another activty.

This is the function's code:

@Override
public void onVectorElementClicked(VectorElement arg0, double arg1,
        double arg2, boolean arg3) {

    Intent intent = new Intent(MapActivity.this, DetailPerspectiveActivity.class);
    activity.startActivity(intent);


}

This is the manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.hsrw.landschaftsbilder"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/><application android:icon="@drawable/icon" android:label="@string/app_name" android:allowBackup="false">
    <activity android:name=".activities.MapActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>            
    </activity>
    <activity android:name=".activities.GraphhopperRouteTestActivity">
    </activity>
    <activity android:name=".activities.DetailPerspectiveActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        </activity>
</application>

I'm pretty sure the problem is about "MapActivity.this" but if I change this to MapActivity.this in the manifest the code is still not compilable. That's what eclipse says about the first argument:

No enclosing instance of the type MapActivity is accessible in scope

Thanks in advance!

Answers


In your activity, try to change Intent intent = new Intent(.activities.MapActivity.this, .activities.DetailPerspectiveActivity.class); to Intent intent = new Intent(MapActivity.this, DetailPerspectiveActivity.class); (ie. both MapActivity and DetailPerspectiveActivity).


Your manifest.xml file contains problems. you have declared two activities as launcher which will not work

amend manifest.xml code as following.

Instead of following

<activity android:name=".activities.MapActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>            
</activity>
<activity android:name=".activities.GraphhopperRouteTestActivity">
</activity>
<activity android:name=".activities.DetailPerspectiveActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    </activity>

Use the following code

<activity android:name=".activities.MapActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>            
</activity>
<activity android:name=".activities.GraphhopperRouteTestActivity">
</activity>
<activity android:name=".activities.DetailPerspectiveActivity">
</activity>

Edit: What does this line do in your code.

 Intent intent = new Intent(.activities.MapActivity.this, .activities.DetailPerspectiveActivity.class);

It usually is the following way

 Intent intent = new Intent(FIRST_ACTIVITY.this, SECOND_ACTIVITY.class);

in your case I presume it should be

 Intent intent = new Intent(MapActivity.this, DetailPerspectiveActivity.class);

Need Your Help

Desing pattern for looping with context dependant output

java design-patterns

I have a problem and I would like to know if there is a known pattern to apply. I was thinking about the visitor but I am not sure. The problem is the following: let's say I have a queue of boxes t...

Spring boot @ResponseBody doesn't serialize entity id

java json spring spring-boot

Have a strange problem and can't figure out how to deal with it.