www.91084.com

GVKun编程网logo

android – configChanges =“orientation”不会触发Galaxy Nexus(android:configchanges="orientation")

25

本文的目的是介绍android–configChanges=“orientation”不会触发GalaxyNexus的详细情况,特别关注android:configchanges="orientati

本文的目的是介绍android – configChanges =“orientation”不会触发Galaxy Nexus的详细情况,特别关注android:configchanges="orientation"的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解android – configChanges =“orientation”不会触发Galaxy Nexus的机会,同时也不会遗漏关于 [Android] Activity ConfigChanges 属性、AdView – AndroidManifest.xml中的android:configChanges缺少adActivity、Android AndEngine问题:java.lang.IllegalArgumentException:未找到EGLConfig、android configChange:orientation和manifest不起作用的知识。

本文目录一览:

android – configChanges =“orientation”不会触发Galaxy Nexus(android:configchanges=

android – configChanges =“orientation”不会触发Galaxy Nexus(android:configchanges="orientation")

您好我有一个奇怪的错误,当我想触发galaxy Nexus(4.0.4)上的方向更改时,它根本不会跳转到onConfigurationChanged(配置)功能.
在HTC Desire(4.0.4)上,它可以在没有相同代码的任何问题的情况下工作.甚至在720p的模拟器上它也可以工作.我尝试更新到 Android 4.1,但我仍然遇到同样的问题.

有没有人有同样的问题或任何解决方案?

解决方法

我看到两台设备都运行Android 4.x,但尝试添加screenSize值,如我之前的答案 here中所述.

  [Android] Activity ConfigChanges 属性

[Android] Activity ConfigChanges 属性

通过设置这个属性可以使 Activity 捕捉设备状态变化,以下是可以被识别的内容: 
设置方法:将下列字段用 “|” 符号分隔开,例如:“locale|navigation|orientation

Value Description
mcc The IMSI mobile country code (MCC) has changed — that is, a SIM hasbeen detected and updated the MCC. 移动国家号码,由三位数字组成,每个国家都有自己独立的 MCC,可以识别手机用户所属国家。
mnc The IMSI mobile network code (MNC) has changed — that is, a SIM hasbeen detected and updated the MNC. 移动网号,在一个国家或者地区中,用于区分手机用户的服务商。
locale The locale has changed — for example, the user has selected a new language that text should be displayed in. 用户所在地区发生变化。
touchscreen The touchscreen has changed. (This should never normally happen.)
keyboard The keyboard type has changed — for example, the user has plugged in an external keyboard. 键盘模式发生变化,例如:用户接入外部键盘输入
keyboardHidden The keyboard accessibility has changed — for example, the user has slid the keyboard out to expose it. 用户打开手机硬件键盘
navigation The navigation type has changed. (This should never normally happen.)
orientation The screen orientation has changed — that is, the user has rotated the device. 设备旋转,横向显示和竖向显示模式切换。
fontScale The font scaling factor has changed — that is, the user has selected a new global font size. 全局字体大小缩放发生改变

通过一个例子介绍这个属性的用法: 首先需要修改项目的 manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.androidres.ConfigChangedTesting"
      android:versionCode="1"
      android:versionName="1.0.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".ConfigChangedTesting"
                  android:label="@string/app_name"
                  android:configChanges="keyboardHidden|orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

在 Activity 中添加了 android:configChanges 属性,目的是当所指定属性 (Configuration Changes) 发生改变时,通知程序调用 onConfigurationChanged () 函数。


横竖屏切换时候 activity 的生命周期 android:configChanges

1、不设置 Activity 的 android:configChanges 时,切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次

2、设置 Activity 的 android:configChanges="orientation" 时,切屏还是会重新调用各个生命周期,切横、竖屏时只会执行一次

3、设置 Activity 的 android:configChanges="orientation|keyboardHidden" 时,切屏不会重新调用各个生命周期,只会执行 onConfigurationChanged 方法

今天遇到一个面试题,让写出横屏切换竖屏 Activity 的生命周期。以前好像看到过,当时没用,于是没注意,结果今天有这个题。

网上查了下,总结下:

1、新建一个 Activity,并把各个生命周期打印出来

2、运行 Activity,得到如下信息

onCreate-->

onStart-->

onResume-->

3、按 crtl+f12 切换成横屏时

onSaveInstanceState-->

onPause-->

onStop-->

onDestroy-->

onCreate-->

onStart-->

onRestoreInstanceState-->

onResume-->

4、再按 crtl+f12 切换成竖屏时,发现打印了两次相同的 log

onSaveInstanceState-->

onPause-->

onStop-->

onDestroy-->

onCreate-->

onStart-->

onRestoreInstanceState-->

onResume-->

onSaveInstanceState-->

onPause-->

onStop-->

onDestroy-->

onCreate-->

onStart-->

onRestoreInstanceState-->

onResume-->

5、修改 AndroidManifest.xml,把该 Activity 添加 android:configChanges="orientation",执行步骤 3

onSaveInstanceState-->

onPause-->

onStop-->

onDestroy-->

onCreate-->

onStart-->

onRestoreInstanceState-->

onResume-->

6、再执行步骤 4,发现不会再打印相同信息,但多打印了一行 onConfigChanged

onSaveInstanceState-->

onPause-->

onStop-->

onDestroy-->

onCreate-->

onStart-->

onRestoreInstanceState-->

onResume-->

onConfigurationChanged-->

7、把步骤 5 的 android:configChanges="orientation" 改成 android:configChanges="orientation|keyboardHidden",执行步骤 3,就只打印 onConfigChanged

onConfigurationChanged-->

8、执行步骤 4

onConfigurationChanged-->

onConfigurationChanged-->

总结:

1、不设置 Activity 的 android:configChanges 时,切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次

2、设置 Activity 的 android:configChanges="orientation" 时,切屏还是会重新调用各个生命周期,切横、竖屏时只会执行一次

3、设置 Activity 的 android:configChanges="orientation|keyboardHidden" 时,切屏不会重新调用各个生命周期,只会执行 onConfigurationChanged 方法

补充一点,当前 Activity 产生事件弹出 Toast 和 AlertDialog 的时候 Activity 的生命周期不会有改变

Activity 运行时按下 HOME 键 (跟被完全覆盖是一样的):onSaveInstanceState --> onPause --> onStop      onRestart -->onStart--->onResume


AdView – AndroidManifest.xml中的android:configChanges缺少adActivity

AdView – AndroidManifest.xml中的android:configChanges缺少adActivity

我只是通过添加添加(AdMob)的Google Play库方法来设置我的应用.当我运行模拟器时,add有错误信息:
Missing adActivity with android:configChanges in AndroidManifest.xml

我找到一个修复:

Missing adActivity with android:configChanges in AndroidManifest.xml

修复说明要做以下事情:

“com.google.ads.AdActivity” is declared when using the admob sdk jar in the “libs” folder. >It seems you’re using admob via the google play services library so change:

activity android:name=”com.google.ads.AdActivity”

To

activity android:name=”com.google.android.gms.ads.AdActivity”

Also make sure you add the Meta-data tag:

我试过这个,而CatLog表示将Meta标签改回:

<Meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

我的LogCat:

02-23 14:30:27.091: E/AndroidRuntime(1278): FATAL EXCEPTION: main
02-23 14:30:27.091: E/AndroidRuntime(1278): Process: biz.midl.debtcalculator,PID: 1278
02-23 14:30:27.091: E/AndroidRuntime(1278): java.lang.RuntimeException: Unable to start activity ComponentInfo{biz.midl.debtcalculator/biz.midl.debtcalculator.MainActivity}: java.lang.IllegalStateException: The Meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4242000 but found 0.  You must have the following declaration within the <application> element:     <Meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:2195)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.os.Looper.loop(Looper.java:136)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.ActivityThread.main(ActivityThread.java:5017)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at java.lang.reflect.Method.invokeNative(Native Method)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at java.lang.reflect.Method.invoke(Method.java:515)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at dalvik.system.NativeStart.main(Native Method)
02-23 14:30:27.091: E/AndroidRuntime(1278): Caused by: java.lang.IllegalStateException: The Meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4242000 but found 0.  You must have the following declaration within the <application> element:     <Meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.google.android.gms.common.GooglePlayServicesUtil.n(UnkNown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(UnkNown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.google.android.gms.internal.u.a(UnkNown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.google.android.gms.internal.ag.U(UnkNown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.google.android.gms.internal.ag.a(UnkNown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.google.android.gms.ads.AdView.loadAd(UnkNown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at biz.midl.debtcalculator.MainActivity.onCreate(MainActivity.java:41)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.Activity.performCreate(Activity.java:5231)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:2159)
02-23 14:30:27.091: E/AndroidRuntime(1278):     ... 11 more

这是我的.java:

import java.text.DecimalFormat;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;

public class MainActivity extends Activity {

private AdView adView;

double interestRate;
double r,r1;
int nRemaining,nStarting,nDifference,originalBalance,outstandingBalance,originalTerm;
double minPayment,additionalPayment,newPmt;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    adView = new AdView(this);
    adView.setAdUnitId("xxxxxxxxxxxxxxxxxxxxxxxxxxxx"); //edited out my unitID
    adView.setAdSize(AdSize.BANNER);

    LinearLayout layout = (LinearLayout) findViewById(R.id.ll);
    layout.addView(adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);

这是我的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1" >

    <com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />

我也有我的清单:

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

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

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <Meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:name="com.google.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

        <activity
            android:name="biz.midl.debtcalculator.MainActivity"
            android:label="@string/app_name"
            android:screenorientation="portrait"
            android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="biz.midl.debtcalculator.About"
            android:label="@string/app_name"
            android:screenorientation="portrait"
            android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.ABOUT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

解决方法

你需要离开元数据标签:
<Meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

另外,您需要替换此标签:

<activity
        android:name="com.google.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

用这个(如你所链接的答案中所建议的):

<activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

由于您使用Google Play服务而不是旧版AdMob SDK,因此您需要将com.google.ads.AdActivity中的活动类名称替换为com.google.android.gms.ads.AdActivity

Android AndEngine问题:java.lang.IllegalArgumentException:未找到EGLConfig

Android AndEngine问题:java.lang.IllegalArgumentException:未找到EGLConfig

晚上好!

我一直在修补AndEngine,以便在Android中进行游戏开发.我尝试运行使用AndEngine的Hanoi塔游戏应用程序,但是当我在模拟器中运行该错误时,上述错误仍在运行.这是LogCat:

09-05 21:34:00.948: D/dalvikvm(633): No JNI_OnLoad found in   /data/data/com.tutorial.towerofhanoi/lib/libandengine.so 0x4101f730, skipping init
09-05 21:34:01.017: D/AndEngine(633): TowerOfHanoiActivity.onResume @(Thread: 'main')
09-05 21:34:01.067: I/dalvikvm(633): threadid=3: reacting to signal 3
09-05 21:34:01.137: I/dalvikvm(633): Wrote stack traces to '/data/anr/traces.txt'
09-05 21:34:01.207: D/libEGL(633): Emulator without GPU support detected. Fallback to software renderer.
09-05 21:34:01.207: D/libEGL(633): loaded /system/lib/egl/libGLES_android.so
09-05 21:34:01.238: W/dalvikvm(633): threadid=12: thread exiting with uncaught exception (group=0x409c01f8)
09-05 21:34:01.297: E/AndroidRuntime(633): FATAL EXCEPTION: GLThread 85
09-05 21:34:01.297: E/AndroidRuntime(633): java.lang.IllegalArgumentException: No EGLConfig found!
09-05 21:34:01.297: E/AndroidRuntime(633):  at org.andengine.opengl.view.ConfigChooser.chooseConfig(ConfigChooser.java:183)
09-05 21:34:01.297: E/AndroidRuntime(633):  at org.andengine.opengl.view.ConfigChooser.chooseConfig(ConfigChooser.java:157)
09-05 21:34:01.297: E/AndroidRuntime(633):  at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1009)
09-05 21:34:01.297: E/AndroidRuntime(633):  at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1362)
09-05 21:34:01.297: E/AndroidRuntime(633):  at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
09-05 21:34:01.309: D/gralloc_goldfish(633): Emulator without GPU emulation detected.
09-05 21:34:01.497: D/AndEngine(633): TowerOfHanoiActivity.onPause @(Thread: 'main')
09-05 21:34:03.867: I/Process(633): Sending signal. PID: 633 SIG: 9

受错误影响的代码行在AndEngine库本身中,尤其是以下行:

            throw new IllegalArgumentException("No " + EGLConfig.class.getSimpleName() + " found!");

屏幕截图显示了我正在构建的目标.这是API15 Android 4.0.3

我该如何补救?

解决方法:

我认为问题在于这条线

09-05 21:34:01.207:D / libEGL(633):未检测到GPU支持的仿真器.退回到软件渲染器.

重新创建或编辑模拟器,并确保在硬件列表下

GPU仿真设置为是

android configChange:orientation和manifest不起作用

android configChange:orientation和manifest不起作用

我使用过Web视图.加载网页.当我改变方向时,它会重新加载.我想停止重装.我在清单 XML文件中进行了以下更改.
它适用于 Android 2.2,但不适用于Android 4.0.我是初学者,任何人都可以提供解决方案.

我的Manifest.xml是;

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="application.eag"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main"
            android:configChanges="orientation|screenSize|keyboardHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

解决方法

<activity
    android:name=".ActivityName"
    android:configChanges="orientation|screenSize|keyboardHidden"/>

将screenSize用于新版本.某些版本可能不支持orientation,需要使用screenSize for configChanges

今天关于android – configChanges =“orientation”不会触发Galaxy Nexusandroid:configchanges="orientation"的介绍到此结束,谢谢您的阅读,有关 [Android] Activity ConfigChanges 属性、AdView – AndroidManifest.xml中的android:configChanges缺少adActivity、Android AndEngine问题:java.lang.IllegalArgumentException:未找到EGLConfig、android configChange:orientation和manifest不起作用等更多相关知识的信息可以在本站进行查询。

本文标签: