Android开始启动错误的活动

时间:2015-04-03 10:52:59

标签: android android-intent android-activity android-manifest

我已将我想要首先从MainActivity运行的活动更改为另一个。我这样做是通过编辑Android清单并移动这段代码来实现的:

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

我的清单现在看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="si.comtron.tronpos" >
<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-feature android:name="android.hardware.usb.host" />

<!-- calendar -->
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />

<!-- camera -->
<uses-permission android:name="android.permission.CAMERA" />

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

<!-- client -->
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<!-- Authenticator -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<!-- Shortcut -->
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<!-- Wifi -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<android:uses-permission android:name="android.permission.READ_PHONE_STATE" />
<android:uses-permission
    android:name="android.permission.READ_EXTERNAL_STORAGE"
    android:maxSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar"
    tools:replace="android:icon,android:theme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:screenOrientation="sensor"
        android:windowSoftInputMode="adjustNothing" >
    </activity>
    <activity
        android:name=".bluetooth.DeviceListActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/select_device"
        android:screenOrientation="sensor" />

<!-- android:windowSoftInputMode="stateVisible|adjustResize" -->
<activity
    android:name=".BasicDataActivity"
    android:label="@string/app_name"
    android:screenOrientation="sensor" >
</activity>
<activity
    android:name=".AnalysisActivity"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:screenOrientation="sensor" />
<activity
    android:name=".authorization.AuthenticatorActivity"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/account_register"
    android:screenOrientation="sensor" />
<activity
    android:name=".authorization.LocalAuthenticatorActivity"
    android:label="@string/account_register"
    android:screenOrientation="sensor" />
<activity
    android:name=".authorization.SingUpActivity"
    android:label="@string/account_register"
    android:screenOrientation="sensor" />

<service android:name=".authorization.TronPosAuthenticatorService" >
    <intent-filter>
        <action android:name="android.accounts.AccountAuthenticator" />
    </intent-filter>

    <meta-data
        android:name="android.accounts.AccountAuthenticator"
        android:resource="@xml/authenticator" />
</service>
<activity
    android:name=".CountryPicker"
    android:label="@string/app_name"
    android:noHistory="true" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
    android:name=".UnitActivity"
    android:label="@string/title_activity_unit" >
</activity>

当我在手机和平​​板电脑(从Android工作室)上运行时,我收到以下错误,应用程序会像以前一样自动启动。但是,当我点击图标时,它首先会以正确的活动正常启动。

但是当我使用模拟器时,正确的活动仅在首次安装时启动,然后先前设置的活动就会启动。

我不知道为什么会这样。我完全卸载了应用程序并重新安装,我清理了我的项目,重建了它,没有什么似乎有所作为,我在我的清单中找不到问题。有什么想法吗?

错误:

Launching application: com.package/com.package.MainActivity.
DEVICE SHELL COMMAND: am start -D -n "com.package/com.package.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=si.comtron.tronpos/.MainActivity }
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=si.comtron.tronpos/.MainActivity } from null (pid=3636, uid=2000) not exported from uid 10104
at android.os.Parcel.readException(Parcel.java:1465)
at android.os.Parcel.readException(Parcel.java:1419)
at android.app.ActivityManagerProxy.startActivityAsUser(ActivityManagerNative.java:2211)
at com.android.commands.am.Am.runStart(Am.java:680)
at com.android.commands.am.Am.onRun(Am.java:270)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
at com.android.commands.am.Am.main(Am.java:76)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:243)
at dalvik.system.NativeStart.main(Native Method)

3 个答案:

答案 0 :(得分:0)

更改启动器活动后,您是否清理过项目?如果没有,那么可以解决你的问题。

答案 1 :(得分:0)

如果您使用的是Eclipse,则可能需要Project - &gt; Clean您的项目。 如果您使用的是Android Studio,则可以执行以下操作:Build ---&gt; Rebuild ProjectClean Project。也许缓存导致这样的事情。

PS:请参阅java.lang.SecurityException: Permission Denial: starting Intent,您需要添加一些权限。

答案 2 :(得分:0)

你可以改变这些

吗?
<android:uses-permission android:name="android.permission.READ_PHONE_STATE" />
<android:uses-permission
    android:name="android.permission.READ_EXTERNAL_STORAGE"
    android:maxSdkVersion="18" />

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission
    android:name="android.permission.READ_EXTERNAL_STORAGE"
     />