Launching an activity from inside a SurfaceView
I'm trying to start an Activity (StartGame) from inside of a SurfaceView once I touch in a certain spot. This code is inside the OnTouchEvent
It won't accept what I have below, of course, but I don't know what to put in the Context space.
I've tried my package (com.Juggle2.Menu), but that doesn't work, because it can't resolve it to a variable, and "this" doesn't work because开发者_如何学JAVA it's a class. I don't know what else to try.
startActivity(new Intent(com.Juggle2.Menu, StartGame.class));
This does not work because "com.Juggle2.Menu cannot be resolved to a variable"
My Manifest is as follows
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Juggle2"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Menu"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".StartGame">
</activity>
<activity android:name = ".Help">
</activity>
<activity android:name = ".Options">
</activity>
<activity android:name = ".Credits">
</activity>
</application>
And my project goes com.Juggle2>Menu.java
Try startActivity(new Intent(com.Juggle2.Menu.this, StartGame.class));
Edit working:
Context context = com.Juggle2.Menu.this.getContext();
context.startActivity(new Intent(context, StartGame.class));
精彩评论