0
startActivity(new Intent(this, SettingsActivity.class));

在 4.0 上为我的一位用户提供了此错误的实例:

java.lang.SecurityException: Not allowed to start activity Intent { cmp=co.bandicoot.ztrader/.activity.SettingsActivity }
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1675)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1442)
    at android.app.Activity.startActivityForResult(Activity.java:3474)
    at android.app.Activity.startActivityForResult(Activity.java:3435)
    at android.support.v4.app.FragmentActivity.startActivityForResult(SourceFile:839)
    at android.app.Activity.startActivity(Activity.java:3677)
    at android.app.Activity.startActivity(Activity.java:3645)
    at co.bandicoot.ztrader.activity.MainActivity.onOptionsItemSelected(SourceFile:3446)
    .....

这是我的 SettingsActivity 清单声明:

<activity
    android:name="co.bandicoot.ztrader.activity.SettingsActivity"
    android:label="@string/action_settings"
    android:parentActivityName="co.bandicoot.ztrader.activity.MainActivity"
    android:screenOrientation="portrait" >
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="co.bandicoot.ztrader.activity.MainActivity" />
</activity>

有任何想法吗?

编辑:这是我的完整清单。这里有什么问题吗?我正在查看 SettingsActivity ,似乎其中没有任何可能需要额外权限的东西。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="co.bandicoot.ztrader"
    android:versionCode="110"
    android:versionName="3.5.2" >

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/Theme.Ztraderdarkactionbar" >
        <receiver android:name=".TickerAlarm" >
        </receiver>
        <receiver android:name=".FastAlarm" >
        </receiver>
        <receiver android:name=".DownloadCurrencyPairsTask" >
        </receiver>
        <receiver android:name=".AutoStart" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" >
                </action>
            </intent-filter>
        </receiver>

        <service android:name="KillNotificationService" >
        </service>

        <activity
            android:name="co.bandicoot.ztrader.activity.MainActivity"
            android:configChanges="orientation"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:uiOptions="splitActionBarWhenNarrow"
            android:windowSoftInputMode="stateHidden" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="co.bandicoot.ztrader.activity.CreateKeyActivity"
            android:label="@string/create_key"
            android:parentActivityName="co.bandicoot.ztrader.activity.MainActivity"
            android:screenOrientation="portrait" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="co.bandicoot.ztrader.activity.MainActivity" />
        </activity>
        <activity
            android:name="co.bandicoot.ztrader.activity.HistoryActivity"
            android:label="@string/history"
            android:parentActivityName="co.bandicoot.ztrader.activity.MainActivity"
            android:screenOrientation="portrait" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="co.bandicoot.ztrader.activity.MainActivity" />
        </activity>
        <activity
            android:name="co.bandicoot.ztrader.activity.SettingsActivity"
            android:label="@string/action_settings"
            android:parentActivityName="co.bandicoot.ztrader.activity.MainActivity"
            android:screenOrientation="portrait" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="co.bandicoot.ztrader.activity.MainActivity" />
        </activity>
        <activity
            android:name="co.bandicoot.ztrader.activity.ChartActivity"
            android:label="@string/app_name"
            android:parentActivityName="co.bandicoot.ztrader.activity.MainActivity"
            android:screenOrientation="landscape"
            android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="co.bandicoot.ztrader.activity.MainActivity" />
        </activity>
        <activity
            android:name="co.bandicoot.ztrader.activity.ManagePairsActivity"
            android:label="@string/pairs"
            android:screenOrientation="portrait" >
        </activity>
    </application>

</manifest>
4

2 回答 2

1

I think it is much more likely that your app/SettingsActivity has decided to go into the background/exit by the time that startActivity was invoked. Yes I am aware that the stacktrace shows it is occurring on the UI thread and so the Activity shouldn't be able to finish while that is occurring, but there appear to be some bugs in the support libraries that aren't handling the Activity/Fragment lifecycle very well is some edge cases.

I think your user hit one of these edge cases.

于 2014-12-18T20:14:06.363 回答
0

我将其写为评论,但我将其添加到此处。从链接

机器人:名称

实现服务的服务子类的名称。这应该是一个完全限定的类名(例如,“com.example.project.RoomService”)。但是,作为简写,如果名称的第一个字符是句点(例如,“.RoomService”),则将其附加到元素中指定的包名称中。

因此,尝试将您的服务更改为:

 <service android:name=".KillNotificationService" >
    </service>
于 2014-10-09T18:35:36.203 回答