Android模拟器未向前台启动活动

时间:2012-04-24 15:32:03

标签: java android eclipse emulation robotium

我正在使用Robotium在Eclipse中运行自动化测试(将其作为Android jUnit测试运行),当我第一次启动模拟器时,应用程序将无法在前台运行并且测试失败。如果我保持模拟器打开按“主菜单”按钮然后运行测试它工作正常。测试在一个记事本的测试项目中运行一些事件。

在第一次打开模拟器时将应用程序推到前台的任何解决方案?

以下是测试项目的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.jayway.test"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
    <uses-library android:name="android.test.runner" />

这是实际项目的清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.notepad" >

    <application android:icon="@drawable/app_notes"
        android:label="@string/app_name" >
        <provider android:name="NotePadProvider"
            android:authorities="com.example.notepad.provider.NotePad" />

        <activity android:name="NotesList"
            android:label="@string/title_notes_list">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.intent.action.EDIT" />
                <action android:name="android.intent.action.PICK" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.GET_CONTENT" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
            </intent-filter>
        </activity>

        <activity android:name="NoteEditor"
            android:theme="@android:style/Theme.Light"
            android:configChanges="keyboardHidden|orientation">
            <!-- This filter says that we can view or edit the data of
                 a single note -->
            <intent-filter android:label="@string/resolve_edit">
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.intent.action.EDIT" />
                <action android:name="com.android.notes.action.EDIT_NOTE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
            </intent-filter>
        </activity>

        <activity android:name="NotesLiveFolder" android:label="@string/live_folder_name"
            android:icon="@drawable/live_folder_notes">
            <intent-filter>
                <action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

    </application>

    <uses-sdk android:minSdkVersion="10"/>
</manifest>
    </application>
    <uses-sdk android:minSdkVersion="10" />
    <instrumentation android:targetPackage="com.example.android.notepad"   android:name="android.test.InstrumentationTestRunner" />
</manifest> 

1 个答案:

答案 0 :(得分:1)

我使用此命令解决了这个问题。

adb shell输入keyevent 82

这会唤醒模拟器/设备。

相关问题