0

アプリを Eclipse から Studio 0.2.1 に移動した後、画面が回転するとアプリが誤動作します。

Nexus7 (およびそれ以上)、Samsung Galaxy S4、およびそれより小さいデバイス (可能であれば) で、アプリが横向きと縦向きの両方をサポートするようにしたいと考えています。

AndroidManifest.xml ファイルは同一です。

アプリは、land>port および port>land から同じように失敗します。

画面を回転させると、次のメソッドが呼び出されます。

  • onSaveInstanceState;
  • onStop;
  • OnDestroy。

アプリには onSaveInstanceState と onRestoreInstanceState の両方も含まれていますが、これらのメソッドにどのコードを配置する必要があるのか​​ 、まったくわかりません。

OnDestroy には、「android.os.Process.killProcess(android.os.Process.myPid())」というコードが含まれます。

...killProcess... コードを削除し、可能であれば Android ライフ サイクル ガイドラインに従ってアプリを実行したいと考えています。

しかし、...killProcess... コードを削除すると、画面を手動で回転させると、アクション バーが保持できる数のメニュー項目で満たされます (Eclipse と Studio 0.2.1 の両方で)。...killProcess... コードに頼る前に、マニフェストの変更とコードの変更の多くの組み合わせを試しました。

2013 年 7 月 26 日の夜、Android バージョン 4.3 が私の Nexus7 にロードされました。2013 年 7 月 27 日の朝に行ったテストでも同じ結果が得られました。

Android Studio は地球上で最高の開発環境であるため、Eclipse に移植する必要がないことを願っています。

前もって感謝します。

以下に関連するコードをいくつか示します。

/**  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