How to retain the state of a activity that has a GLSurfaceView

Posted by user348639 on Stack Overflow See other posts from Stack Overflow or by user348639
Published on 2010-05-24T04:34:48Z Indexed on 2010/05/24 4:41 UTC
Read the original article Hit count: 334

Filed under:
|
|

My problem is our game can switch into menu and setting mode instantly but it will need 4-6 seconds to load texture, init GL render mode eventually I just used 6 simple textures to create 6 sprites in game.

Please help me answer two questions: 1. How can I preload our assets in android os to start our game quicker? 2. In order to use a trick to create instance switch between activity, how can I retain my activity with GLSurfaceView state?

I order to help you understanding my situation, please read the following code:

The game using 3 activities as you can see in following configuration:

 <application android:label="@string/app_name"
  android:icon="@drawable/icon" android:allowBackup="true">
  <activity android:name=".Menu" android:screenOrientation="portrait" 
  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
  android:launchMode="singleTop">
   <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>

  </activity>
  <activity android:name=".ReTouch" android:screenOrientation="portrait" />

  <activity android:name=".Preference" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />

 </application>

My .ReTouch class is a class that extended from RokonActivity (I am using rokon engine for my game), this engine will create a GLSurefaceView to render my game in OpenGL ES You can get RokonAcitivity's source code here: http://code.google.com/p/rokon/source/browse/tags/release/1.1.1/src/com/stickycoding/Rokon/RokonActivity.java

 public class ReTouch extends RokonActivity {
 public static final int REPLAY_DELAY_INTERVAL = 1000;
 private ReTouchGameBoard reTouchGame;

and .Menu, .Preference are two normal standard activity in an android application.

I am using this method to start and switch between activities:

  playButton.setOnClickListener(new OnClickListener() {

   public void onClick(View v) {
    soundPool.play(soundId, 1, 1, 1, 0, 1);
    startActivity(new Intent(Menu.this, ReTouch.class));
   }
  });
  settingButton.setOnClickListener(new OnClickListener() {

   public void onClick(View v) {
    soundPool.play(soundId, 1, 1, 1, 0, 1);
    startActivity(new Intent(Menu.this, Preference.class));
   }
  });
  quitButton.setOnClickListener(new OnClickListener() {

   public void onClick(View v) {
    soundPool.play(soundId, 1, 1, 1, 0, 1);
    finish();
   }
  });

© Stack Overflow or respective owner

Related posts about android

Related posts about game