[英]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.一旦我触摸某个位置,我就会尝试从 SurfaceView 内部启动一个 Activity (StartGame)。 This code is inside the OnTouchEvent
此代码在 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.我已经尝试过我的 package(com.Juggle2.Menu),但这不起作用,因为它无法将其解析为变量,并且“this”不起作用,因为它是 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"这不起作用,因为“com.Juggle2.Menu 无法解析为变量”
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我的项目是 com.Juggle2>Menu.java
Try startActivity(new Intent(com.Juggle2.Menu.this, StartGame.class));试试 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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.