我只有一个最简单的应用程序:
MainActivity.java
package com.example.simplestedittext;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hello_world" >
</EditText>
</LinearLayout>
每当我旋转屏幕时,我都会在 Eclipse 中收到这条消息:
03-28 09:54:46.624: I/TextView(2778): [android.widget.EditText@405320b0 is not instanceof CheckBox] === ss.text 是
如果我在 EditText 框中输入了“aaa”,则消息将是:
03-28 09:54:53.593: I/TextView(2778): [android.widget.EditText@40541820 is not instanceof CheckBox] === ss.text 是 aaa
那条消息是什么意思?我的应用程序有问题吗?
而且,你有这些信息吗?
编辑:
好吧,刚刚注意到,它不仅会在屏幕旋转时发生,而且在切换回此应用程序时也会发生。(不,对不起,不再)
我有突破!
我确定该消息是从super.onRestoreInstanceState();
MainActivity.java
package com.example.simplestedittext;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
System.out.println("before");
super.onRestoreInstanceState(savedInstanceState);
System.out.println("after");
}
}
并且输出消息变为:
03-28 10:33:36.515: I/System.out(4147): before
03-28 10:33:36.515: I/TextView(4147): [android.widget.EditText@4053a138 is not instanceof CheckBox] === ss.text is
03-28 10:33:36.523: I/System.out(4147): after
03-28 10:33:44.328: I/System.out(4147): before
03-28 10:33:44.328: I/TextView(4147): [android.widget.EditText@40549128 is not instanceof CheckBox] === ss.text is aaa
03-28 10:33:44.328: I/System.out(4147): after
希望它可以帮助你帮助我:-)
编辑2:
请注意:没有什么是崩溃的。我只是对“信息”级别的日志消息感到好奇(并且不满意):-/
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testorientation"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.testorientation.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>