我正处于 Cocos2d - Android 游戏的最后阶段,我遇到了一个我无法解决的问题。
当我锁定我的平板电脑 (Nexus 7) 或当我按下主页按钮离开游戏时,它会重新启动。它就像游戏重新打开一样回到启动画面。供您参考,这是我的主要活动和我的 Android 清单:
public class MainActivity extends Activity {
//To get a static reference to context for shared preferences
private static Context context;
protected CCGLSurfaceView _glSurfaceView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//To get a static reference to context for shared preferences
MainActivity.context = getApplicationContext();
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
_glSurfaceView = new CCGLSurfaceView(this);
setContentView(_glSurfaceView);
}
//To get a static reference to context for shared preferences
public static Context getAppContext(){
return MainActivity.context;
}
@Override
public void onStart()
{
super.onStart();
CCDirector.sharedDirector().attachInView(_glSurfaceView);
CCDirector.sharedDirector().setDeviceOrientation(CCDirector.kCCDeviceOrientationPortrait);
CCDirector.sharedDirector().setDisplayFPS(true);
CCDirector.sharedDirector().setAnimationInterval(1.0f / 60.0f);
CCScene scene = Splash.scene();
CCDirector.sharedDirector().runWithScene(scene);
}
@Override
public void onPause()
{
super.onPause();
CCDirector.sharedDirector().pause();
SoundEngine.sharedEngine().pauseSound();
}
@Override
public void onResume()
{
super.onResume();
CCDirector.sharedDirector().resume();
SoundEngine.sharedEngine().resumeSound();
}
@Override
public void onStop()
{
super.onStop();
SoundEngine.sharedEngine().pauseSound();
}
和
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bigfiresoftware.alphadefender"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/adicon"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="bigfiresoftware.alphadefender.MainActivity"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:hardwareAccelerated="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
android:configChanges="keyboard|keyboardHidden|orientation"
</manifest>
非常感谢任何/所有帮助。谢谢。