0

将我的应用程序从 Eclipse 移动到 Studio 0.2.1 后,屏幕旋转会导致应用程序出现故障。

我希望我的应用在 Nexus7(和更大)、三星 Galaxy S4 和更小的设备(如果可能)上支持横向和纵向。

AndroidManifest.xml 文件是相同的。

该应用程序从陆地>港口和港口>陆地同样失败。

旋转屏幕时,会调用以下方法:

  • onSaveInstanceState;
  • 停止;
  • 销毁。

该应用程序还包含 onSaveInstanceState 和 onRestoreInstanceState,但我不知道需要在这些方法中放置什么代码。

OnDestroy 包含代码:“android.os.Process.killProcess(android.os.Process.myPid())”。

如果可能,我想删除 ...killProcess... 代码并让我的应用根据 Android 生命周期指南执行。

但是,如果我删除 ...killProcess... 代码,当手动旋转屏幕时,操作栏会充满尽可能多的菜单项(在 Eclipse 和 Studio 0.2.1 上)。在诉诸 ...killProcess... 代码之前,我尝试了许多清单更改和代码更改的组合。

Android 4.3 版在 2013 年 7 月 26 日晚上加载到我的 Nexus7 上。我在 2013 年 7 月 27 日早上的测试产生了相同的结果。

我希望我不必移植回 Eclipse,因为 Android Studio 是这个星球上最好的开发环境。

提前致谢。

下面找到一些相关代码:

/**  Start Processing  */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /**  Don't know what this does !!  */
    //ActionMode mActionMode;
    // mSearchText = new TextView(this);
    // setContentView(mSearchText);
    //ActionMode mContextMode = startActionMode(mActionModeCallback);


    /** Set up openGL environment */
    setContentView(R.layout.vjn_menu);
    mGLSurfaceView = (VjnGLSurfaceView) findViewById(R.id.gl_surface_view);


    // Check if the system supports OpenGL ES 2.0.
    final ActivityManager activityManager = (ActivityManager)  getSystemService(Context.ACTIVITY_SERVICE);
    final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
    final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;

    if (supportsEs2)
    {
        // Request an OpenGL ES 2.0 compatible context.
        mGLSurfaceView.setEGLContextClientVersion(2);
        final DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        // Set the renderer.
        mRenderer = new VjnRenderer(this);
        mGLSurfaceView.setRenderer(mRenderer, displayMetrics.density);
    }
}

/**
 * onResume notifies OpenGL of resume event.
 */
@Override
protected void onResume()
{
    /**  Restore preferences  */
    getPrefs();

    /***  Disabled --------------
    if(mStopped && mActions == "<>")
    {
        Toast.makeText(this, "PREFS_NAME NOT changed.", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(this, "PREFS_NAME CHANGED from default.", Toast.LENGTH_SHORT).show();
    }
     ---------------*/

    super.onResume();
    mGLSurfaceView.onResume();

    return;
}


/**
 * onPause notifies OpenGL of pause event.
 */
@Override
protected void onPause()
{
    super.onPause();
    mGLSurfaceView.onPause();
    return;

}
/**
 * onStop saves this method's preferences.
 */
@Override
protected void onStop(){
    super.onStop();

    putPrefs(PREFS_NAME);  // Commit Preferences

    return;
}

protected void onSaveInstanceState (Bundle savedInstanceState)
{
    super.onSaveInstanceState(savedInstanceState);
    putPrefs(PREFS_NAME);  // Commit Preferences
    Toast.makeText(this, "onSaveInstanceState entered.", Toast.LENGTH_SHORT).show();
    return;
}

protected void onRestoreInstanceState (Bundle savedInstanceState)
{
    super.onRestoreInstanceState(savedInstanceState);
    Toast.makeText(this, "onRestoreInstanceState entered.", Toast.LENGTH_SHORT).show();
    return;
}

protected void onDestroy(){
    super.onDestroy();
    Toast.makeText(this, "onDestroy entered.", Toast.LENGTH_SHORT).show();
    //android.os.Process.killProcess(android.os.Process.myPid());
    return;
}

public void onConfigurationChanged (Configuration newConfig)
{
    super.onConfigurationChanged(newConfig);
    Toast.makeText(this, "onConfigurationChanged entered.", Toast.LENGTH_SHORT).show();
    return;
}

/**  Create Options Menu  */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    try
    {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.actions, menu);
    }
    catch (InflateException e)
    { // Number not a floating point number
        Toast.makeText(this, "InflateException in onCreateOptionsMenu.", Toast.LENGTH_SHORT).show();
    }

    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setOnQueryTextListener(this);
    return true;
}


@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    /**  Save original Action Bar titles for later use  */
    if (! onPrepare) // Have we prepared for this menu?
    { // Prime ActionBar control for Object (model, assembly & sub-assembly)
        onPrepare = true;  // First time through onPrepareOptionMenu: Done
        ActionBar.DefineVisibility(menu);  // True logic

        /**  First time processing: activate GoTo menu structure ---------------------- */
        int[] mGoToVis = { ABgoTo, 1 };
        boolean mReturn1 = ActionBar.OnlyVisible(mGoToVis);
        if (!mReturn1) // Success?
        { // No
            Toast.makeText(this, "onPrepareOptionsMenu, SetVisibility error 1.", Toast.LENGTH_SHORT).show();
        }


        //ActionBar.DisableTools();

    }

    /**  Always activate GoTo menu structure ---------------------- */
    int[] mGoToVis = { ABgoTo, 1 };
    int[] mReturn1 = ActionBar.SetVisibility(mGoToVis);
    if (mReturn1[0] == (-1)) // Success?
    { // No
        Toast.makeText(this, "onPrepareOptionsMenu, SetVisibility error 1.", Toast.LENGTH_SHORT).show();
    }

    /**  Control the visibility of Action Bar GoTo menus  */
    if (mIsModelValid) // Is Model ID valid?
    { // Yes, set "Tools", "Object" and "Magnifying Glass" visible

    } else
    { // No, set "Object" and "Magnifying Glass" visible
        int[] mModelInvalid = {ABobject, 1};
        int[] mReturn2 = ActionBar.SetVisibility(mModelInvalid);
        if (mReturn2[0] == (-1)) // Success?
        { // No
            Toast.makeText(this, "onPrepareOptionsMenu, SetVisibility error 2.",
                    Toast.LENGTH_SHORT).show();
        }
    }


    .
    .
    .


    /**  TEST:  if we stopped last execution, disable & set not visible "Tools"
     if (m2ndPass)
     {
     boolean mDtStatus = ActionBar.DisableTools();
     if (! mDtStatus)
     {
     Toast.makeText(this, "DisableTools failed.", Toast.LENGTH_SHORT).show();
     } else {
     Toast.makeText(this, "DisableTools SUCCESS!.", Toast.LENGTH_SHORT).show();
     }
     }
     ------------ */

    return super.onPrepareOptionsMenu(menu);

} // End of onPrepareOptionsMenu

protected void onRestoreInstanceState (Bundle savedInstanceState)
{
    super.onRestoreInstanceState(savedInstanceState);
    Toast.makeText(this, "onRestoreInstanceState entered.", Toast.LENGTH_SHORT).show();
    return;
}






<!-- SORT menu follows  -->
<item android:id="@+id/action_sort"
      android:enabled="false"
      android:icon="@android:drawable/ic_menu_sort_by_size"
      android:title="@string/action_bar_sort"
      android:showAsAction="never">
    <menu>
        <item android:id="@+id/action_sort_size"
              android:icon="@android:drawable/ic_menu_sort_by_size"
              android:title="@string/action_bar_sort_size"
              android:onClick="onSort" />

        <item android:id="@+id/action_sort_alpha"
              android:icon="@android:drawable/ic_menu_sort_alphabetically"
              android:title="@string/action_bar_sort_alpha"
              android:onClick="onSort" />
    </menu>
</item>



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ghyrome.objectworld1"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="17"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ow_icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.ghyrome.objectworld1.MainActivity"
        android:label="@string/app_name" >
        android:configChanges="orientation|screenSize"
        android:clearTaskOnLaunch="true"
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

 </manifest>


 <?xml version="1.0" encoding="UTF-8"?>
 <module external.system.id="GRADLE" type="JAVA_MODULE" version="4">
   <component name="FacetManager">
     <facet type="android" name="Android">
     <configuration>
    <option name="SELECTED_BUILD_VARIANT" value="Debug" />
    <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
    <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleTest" />
    <option name="ALLOW_USER_CONFIGURATION" value="false" />
    <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
    <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
    <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
  </configuration>
</facet>
<facet type="android-gradle" name="Android-Gradle">
  <configuration>
    <option name="GRADLE_PROJECT_PATH" value=":ObjectWorld1" />
  </configuration>
</facet>
 </component>
 <component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
  <sourceFolder url="file://$MODULE_DIR$/build/source/r/debug" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/build/source/aidl/debug" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/build/source/rs/debug" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/debug" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/build/res/rs/debug" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/build/source/r/test" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/build/source/aidl/test" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/build/source/rs/test" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/test" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/build/res/rs/test" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/src/debug/res" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/src/main/res" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/aidl" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/assets" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/java" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/jni" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/rs" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/res" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/resources" isTestSource="true" />
  <excludeFolder url="file://$MODULE_DIR$/build/apk" />
  <excludeFolder url="file://$MODULE_DIR$/build/assets" />
  <excludeFolder url="file://$MODULE_DIR$/build/bundles" />
  <excludeFolder url="file://$MODULE_DIR$/build/classes" />
  <excludeFolder url="file://$MODULE_DIR$/build/dependency-cache" />
  <excludeFolder url="file://$MODULE_DIR$/build/exploded-bundles" />
  <excludeFolder url="file://$MODULE_DIR$/build/incremental" />
  <excludeFolder url="file://$MODULE_DIR$/build/libs" />
  <excludeFolder url="file://$MODULE_DIR$/build/manifests" />
  <excludeFolder url="file://$MODULE_DIR$/build/symbols" />
  <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android 4.2.2 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="support-v4-13.0.0" level="project" />
  </component>
  </module>

    <?xml version="1.0" encoding="utf-8"?>
   <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"  
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.ghyrome.objectworld1.VjnGLSurfaceView
    android:id="@+id/gl_surface_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
    </FrameLayout>
4

0 回答 0