激活时,我的应用正在充分处理屏幕方向更改并且稳定。
但如果应用程序不可见(按下主页按钮后)应用程序崩溃屏幕方向更改(我看到主屏幕,我看到主页屏幕转为横向),并出现以下错误:
02-10 14:24:00.361 1660-1660/de.mydomain.MyApp E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.mydomain.MyApp, PID: 1660
android.view.InflateException: Binary XML file line #31: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at com.android.internal.widget.ActionBarContextView.initClose(ActionBarContextView.java:330)
at com.android.internal.widget.ActionBarContextView.onConfigurationChanged(ActionBarContextView.java:185)
at android.view.View.dispatchConfigurationChanged(View.java:8599)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1105)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1110)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1110)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1110)
at android.view.ViewRootImpl.updateConfiguration(ViewRootImpl.java:3441)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3612)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at com.android.internal.widget.ActionBarContextView.initClose(ActionBarContextView.java:330)
at com.android.internal.widget.ActionBarContextView.onConfigurationChanged(ActionBarContextView.java:185)
at android.view.View.dispatchConfigurationChanged(View.java:8599)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1105)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1110)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1110)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1110)
at android.view.ViewRootImpl.updateConfiguration(ViewRootImpl.java:3441)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3612)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=24; index=230
at android.content.res.StringBlock.get(StringBlock.java:65)
at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:459)
at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:721)
at android.content.res.TypedArray.getString(TypedArray.java:125)
at android.widget.TextView.<init>(TextView.java:1509)
at android.widget.TextView.<init>(TextView.java:908)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at com.android.internal.widget.ActionBarContextView.initClose(ActionBarContextView.java:330)
at com.android.internal.widget.ActionBarContextView.onConfigurationChanged(ActionBarContextView.java:185)
at android.view.View.dispatchConfigurationChanged(View.java:8599)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1105)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1110)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1110)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1110)
at android.view.ViewRootImpl.updateConfiguration(ViewRootImpl.java:3441)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3612)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
我很难向您展示MainActivity的整个代码,因为它有许多超类并实例化了几个自定义对象。 MainActivity通过使用适配器显示列表并使用数据库连接。
这是视图膨胀的地方:
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.showList(); }
protected void showList() {
this.makeListView();//asignes the ListView to this.listview
this.makeListHelper();//listHelper is building the list to be shown
this.arrayAdapter = new MyListItemStringAdapter(this,this.listHelper.getList());
this.listview.setAdapter(arrayAdapter);
this.listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override public void onItemClick(AdapterView<?> parent, final View view,
int position, long id)
{ didSelectItem(position);
}
});
}
使用的xml:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- headline, optional -->
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/mainHeadlineWrapper"
android:visibility="gone">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" style="@style/headlineBox">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listHeader"
android:textColor="@color/actionbarTextColor"
style="@style/myDefaultTextAppearance.headline"/>
</LinearLayout>
<View android:layout_width="match_parent" android:layout_height="@dimen/mainHeadlineDivider" android:background="@color/mainHeadlineDividerBg"/>
</LinearLayout>
<!-- search wrapper -->
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/mainListSearchWrapper" android:orientation="vertical"/>
<!-- main listView -->
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/main_listView"/>
</LinearLayout>
此错误仅发生在三星表(SM-T311,android 4.4.2)上。我无法在Moto G或华硕平板电脑上重现它。
我不知道如何找到错误。我在错误日志中找不到任何可以指向崩溃原因的内容。
如果您不知道这个特定错误的答案,也许您可以告诉我当应用程序处于活动状态且可见时以及何时不可用时可能会有什么不同。
感谢您的帮助。
[编辑] 我应该提到我试过“keyboardHidden | orientation | screenSize”和android:screenOrientation =“portrait”。 没有任何效果。
[编辑] 我改变了文字,使我的问题更容易理解。 我在应用程序不可见/关闭/在后台搜索屏幕方向更改时发现崩溃,但我发现只处理方向更改的常见问题。
[编辑]
使用清单中的活动,如下所示,应用程序崩溃活动和停止(隐藏,androids主屏幕可见):
<activity android:name=".activities.MainActivity"
android:label="@string/app_name"
android:alwaysRetainTaskState="true"
android:configChanges="orientation|screenSize|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
对于清单中的活动,如下所示,应用程序仅在停止时崩溃(不可见,主机主屏幕可见)并且从纵向更改为横向正常:
<activity android:name=".activities.MainActivity"
android:label="@string/app_name"
android:alwaysRetainTaskState="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
对于清单中的活动,如下所示,应用程序仅在停止时崩溃(不可见,主机主屏幕可见)并且未按预期从纵向更改为横向:
<activity android:name=".activities.MainActivity"
android:label="@string/app_name"
android:alwaysRetainTaskState="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
答案 0 :(得分:0)
你必须添加android:configChanges =&#34; orientation | screenSize | keyboardHidden&#34;在您的清单中,代码必须像这样
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:configChanges="orientation|screenSize|keyboardHidden">