Android 如何保留具有GLSURFACHEVIEW的活动的状态

Android 如何保留具有GLSURFACHEVIEW的活动的状态,android,glsurfaceview,Android,Glsurfaceview,我的问题是我们的游戏可以立即切换到菜单和设置模式,但需要4-6秒来加载纹理,初始化GL渲染模式最终我只使用了6个简单的纹理在游戏中创建了6个精灵 请帮我回答两个问题: 1.如何在android操作系统中预装我们的资产,以便更快地开始游戏? 2.为了使用技巧在活动之间创建实例切换,如何使用GLSURFACHEVIEW状态保留活动 为了帮助您了解我的情况,请阅读以下代码: 游戏使用3种活动,如以下配置所示: <application android:label="@string/app_na

我的问题是我们的游戏可以立即切换到菜单和设置模式,但需要4-6秒来加载纹理,初始化GL渲染模式最终我只使用了6个简单的纹理在游戏中创建了6个精灵

请帮我回答两个问题: 1.如何在android操作系统中预装我们的资产,以便更快地开始游戏? 2.为了使用技巧在活动之间创建实例切换,如何使用GLSURFACHEVIEW状态保留活动

为了帮助您了解我的情况,请阅读以下代码:

游戏使用3种活动,如以下配置所示:

 <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>
和.Menu、.Preference是android应用程序中的两个正常标准活动

我使用此方法启动和切换活动:

  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();
   }
  });

我避免了这个问题,而不是为我的游戏解决它:

我使用“FrameLayout”作为主布局,“GLSurfaceView”作为其内部的第一个布局(即在堆栈的底部),然后使用“menu”视图组,并在其顶部使用不透明的“loading”屏幕(设置为
match\u parent
以填充屏幕):


对于加快纹理的实际加载时间有一些很好的答案

  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();
   }
  });
<FrameLayout 
    android:id="@+id/graphics_frameLayout1" 
    android:layout_width="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent">
    <android.opengl.GLSurfaceView 
        android:id="@+id/graphics_glsurfaceview1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent">
    </android.opengl.GLSurfaceView>
    <LinearLayout
        android:id="@+id/menu_linearLayout1"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:visiblility="gone"
        android:background="#000000">// opaque background
        // menus etc be here
    </LinearLayout>
    <LinearLayout       
        android:layout_height="fill_parent" 
        android:id="@+id/loading_linearLayout1" 
        android:layout_width="fill_parent" 
        android:orientation="vertical"
        android:background="#000000">// opaque background
        <ProgressBar 
            style="?android:attr/progressBarStyleLarge" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/loading_progressBar1">
        </ProgressBar>
        <TextView 
            android:layout_width="wrap_content" 
            android:id="@+id/loading_textView1" 
            android:layout_height="wrap_content" 
            android:text="Loading...">
        </TextView>
    </LinearLayout>
</FrameLayout>