户身份验证器accountPreferences屏幕启动Inte

户身份验证器accountPreferences屏幕启动Inte

本文介绍了从帐户身份验证器accountPreferences屏幕启动Intent?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中包含了AccountManager代码,以使用户能够从其设置"应用程序内部创建和管理其帐户.

I have included the AccountManager code in my app to enable the user to create and manage their account from inside their Settings application.

我在帐户验证器定义内的"accountPreferences"首选项文件中进行了链接,并且这些选项在设置">帐户">我的应用程序"屏幕中正确显示.当我点击其中一个时,我没有得到链接的活动,而是得到了:

I linked in the "accountPreferences" preferences file inside my account-authenticator definition, and the options show properly in the Settings > Accounts > My App screen. When I tap on one of them, instead of getting the activity I linked in, I get:

01-14 14:47:27.304: ERROR/AndroidRuntime(27708): FATAL EXCEPTION: main
    android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
    at android.app.ContextImpl.startActivity(ContextImpl.java:944)
    at android.app.ContextImpl.startActivity(ContextImpl.java:931)
    at android.preference.Preference.performClick(Preference.java:967)
    at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:215)

我在PreferenceScreen中的意图定义为:

I have the intents inside my PreferenceScreen defined as:

<intent
    android:action="android.intent.action.VIEW"
    android:targetPackage="com.myapp.android"
    android:targetClass="com.myapp.android.activities.AccountForwardingActivity"/>

目标活动也按照您的预期进行定义,除了意图过滤器之外没有其他特殊标记可以匹配该动作(我也列出了其他自定义动作).

And the target activity is also defined as you'd expect, with no special flags other than an intent-filter to match that action (I have other custom actions listed as well).

<activity android:name=".activities.AccountForwardingActivity"
    android:theme="@style/Theme.MyApp"
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="com.myapp.android.PAYMENT_TYPES"/>
        <action android:name="com.myapp.android.ADDRESS_LIST"/>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

我做错了什么?我如何将这个从Settings.apk启动的意图标记为一项新任务?

What am I doing wrong? How can I mark this intent, launched from Settings.apk, to be a new task?

推荐答案

我的问题是将首选项"屏幕放在我的PreferenceCategory中.

My problem was putting the Preference Screens inside my PreferenceCategory.

这很好:

<PreferenceCategory android:title="General Settings" />
<PreferenceScreen
    android:title="Account Settings"
    android:summary="Favorites, Orders, and more.">
    <intent
        android:action="android.intent.action.VIEW"
        android:targetPackage="com.myapp.android"
        android:targetClass="com.myapp.android.activities.AccountForwardingActivity"/>
</PreferenceScreen>

嵌套PreferenceCategory中的PreferenceScreen不起作用,并导致上述错误.

Nesting that PreferenceScreen inside the PreferenceCategory does not work, and results in the error above.

这篇关于从帐户身份验证器accountPreferences屏幕启动Intent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 10:34