1

我有一个测试应用程序,它使用其类名启动内部设置活动:

Intent intent = new Intent(this, MyTestAppSettings.class);
startActivity(intent);

在活动出现之前有很长的延迟(对于这个特定的示例为 10 秒),延迟是由于 ActivityManager 启动超时到期。我添加了一些日志语句来显示这种情况,见下文。

对settingsClick的调用发生在主活动中,您会看到 ActivityManager 启动了意图。然后在为启动的活动输入onCreate之前有 10 秒的延迟。在此期间,ActivityManager 会记录 Launch timeout has expired消息。

是什么导致这种类型的超时发生?

05-15 19:46:25.673: I/MyTestApp(9341): settingsClick: Launching MyTestAppSettings activity
05-15 19:46:25.673: I/ActivityManager(1672): Starting: Intent { cmp=com.MyCompany.MyTestApp/.MyTestAppSettingsActivity } from pid 9341
05-15 19:46:26.193: W/ActivityManager(1672): Activity pause timeout for HistoryRecord{4055c610 com.MyCompany.MyTestApp/.MyTestAppActivity}
05-15 19:46:31.683: I/power(1672): *** set_screen_state 1
05-15 19:46:35.693: W/ActivityManager(1672): Launch timeout has expired, giving up wake lock!
05-15 19:46:35.903: I/MyTestAppSettings(9341): onCreate Enter
05-15 19:46:35.923: I/MyTestAppSettings(9341): onCreate Exit
05-15 19:46:35.923: I/MyTestAppSettings(9341): onResume Enter
05-15 19:46:35.923: I/MyTestAppSettings(9341): onResume Exit
05-15 19:46:36.043: I/ActivityManager(1672): Displayed com.MyCompany.MyTestApp/.MyTestAppSettingsActivity: +9s850ms

编辑这是设置活动的代码,目前非常薄,仅测试从主应用程序启动的活动。

@SuppressWarnings("unused")
public class MyTestAppSettingsActivity  extends Activity {
    protected static final String TAG = "MyTestAppSettings";  // for Log.x() calls

    public static final boolean DEBUG_LOGGING = false;         // verbose logging using Log.i()
    public static final boolean DEBUG_PROCS = true;           // enables proc entry/exit logging

    private Context mThisActivityContext = null;
    private Resources mResources = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (DEBUG_PROCS) { Log.i(TAG, "onCreate Enter"); }

        super.onCreate(savedInstanceState);

        setContentView(R.layout.monitor_settings);

        mThisActivityContext = this.getApplicationContext();
        mResources = mThisActivityContext.getResources();

        if (DEBUG_PROCS) { Log.i(TAG, "onCreate Exit"); }
    }

    @Override
    protected void onResume() 
    {
        if (DEBUG_PROCS) { Log.i(TAG, "onResume Enter"); }

        super.onResume();

        if (DEBUG_PROCS) { Log.i(TAG, "onResume Exit"); }
    }

    @Override
    protected void onPause() 
    {
        if (DEBUG_PROCS) { Log.i(TAG, "onPause Enter"); }

        super.onPause();

        if (DEBUG_PROCS) { Log.i(TAG, "onPause Exit"); }
    }

    @Override
    public void onStop() {
        if (DEBUG_PROCS) { Log.i(TAG, "onStop Enter"); }

        super.onStop();

        if (DEBUG_PROCS) { Log.i(TAG, "onStop Exit"); }
    }

}

以及设置活动布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:context=".MainActivity"
    >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="left|center_vertical"
        android:paddingLeft="3dip"
        android:text="@string/displaySystemSettingsHeader"
            style="@style/SettingsHeader"
        />

    <LinearLayout  
        android:id="@+id/layoutSettings"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        <ImageView
            android:id="@+id/imageButtonSettings"
            android:layout_width="36dip"
            android:layout_height="36dip"
            android:clickable="true"
            android:contentDescription="@string/btnSettings"
            android:scaleType="fitStart"
            android:src="@drawable/button_settings" 
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:paddingLeft="3dip"
            android:text="@string/displaySystemSettings"
            style="@style/SettingsEntryTitle"
            />
    </LinearLayout>

   <CheckBox
       android:id="@+id/chkInfoMode"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:gravity="center_vertical"
       style="@style/SettingsEntryTitle"
       android:text="@string/infoButtonMode" />

</LinearLayout>
4

0 回答 0