1

我试图理解片段。我读到的所有例子都是关于有一个主要活动,然后是两个子片段。问题是我的程序只有 1 个活动。我可以把它变成一个片段吗?当前的ui主类

public class MainActivity extends Activity {}

我能做到吗

public class MainActivity extends Fragment {}

我正在尝试创建的程序将不断监控电话变量并在 textView 中显示日志。当用户更改方向或操作系统破坏 ui 时的其他更改时,我不想丢失日志。

UI 基本上是 1 个 textView,它被一个可运行对象填充,该可运行对象每 5 秒使用链表的内容更新 textView。我基本上不想丢失链表的内容。

我检查了 getLastNonConfigurationInstance() 但它似乎已贬值,所以我不想使用它

任何帮助将不胜感激。

阿米什人

4

1 回答 1

-1

在这里找到答案:http: //blog.webagesolutions.com/archives/458

所以经过大量搜索后,我发现如果添加以下内容: android:configChanges="orientation|screenSize"

在androidManifest.xml中,从纵向模式切换到横向模式时,操作系统不会破坏活动。

我的 xml 文件如下所示:

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

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

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

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

</manifest>

希望这对某人有所帮助,阿米什人

于 2012-11-29T03:39:17.510 回答