从 SurfaceView 内部启动 Activity
一旦我触摸某个位置,我就会尝试从 SurfaceView 内部启动一个 Activity (StartGame)。这段代码位于 OnTouchEvent 内部
,当然,它不会接受我下面的内容,但我不知道要在上下文空间中放入什么。
我已经尝试过我的包(com.Juggle2.Menu),但这不起作用,因为它无法将其解析为变量,并且“this”不起作用,因为它是一个类。我不知道还能尝试什么。
startActivity(new Intent(com.Juggle2.Menu, StartGame.class));
这不起作用,因为“com.Juggle2.Menu 无法解析为变量”
我的清单如下
<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>
我的项目是 com.Juggle2>Menu.java
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试 startActivity(new Intent(com.Juggle2.Menu.this, StartGame.class));
编辑工作:
Try startActivity(new Intent(com.Juggle2.Menu.this, StartGame.class));
Edit working: