PreferenceScreen -<意图...>- 异常 - FLAG_ACTIVITY_NEW_TASK

发布于 2024-09-19 21:44:32 字数 2317 浏览 6 评论 0原文

我是android开发的新手。

该项目是关于使用 AbstractThreadedSyncAdapter 实现 AbstractAccountAuthenticator,以将服务器上的某些数据与内容提供者同步。

我做了一切,添加帐户和同步都运行没有任何问题。

现在我尝试通过像这样的xml添加一个Preference-Screen,就像android参考中建议的那样(搜索AbstractAccountAuthenticator,那里有解释):

autenticator.xml:

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="typeOfAuthenticator"
    android:icon="@drawable/icon"
    android:smallIcon="@drawable/miniIcon"
    android:label="@string/label"
    android:accountPreferences="@xml/account_preferences"
 />

The Preference-Screen-xml看起来像这样:

account_preferences.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
 <PreferenceCategory android:title="@string/pref_cat_general">
  <PreferenceScreen android:key="@string/pref_cat_scr_keygen" android:title="@string/pref_cat_scr_keygen_title" android:summary="@string/pref_cat_scr_keygen_summary">
   <intent android:action="android.intent.action.VIEW" android:targetPackage="com.android.clean" android:targetClass="com.android.clean.KeygenAct" />
  </PreferenceScreen>
 </PreferenceCategory>
</PreferenceScreen>

屏幕被提示应该如何,但这就是问题:当我有意点击 PreferenceScreen 时,它会导致系统崩溃(两者)在模拟器和我的 HTC-Desire 中)。

日志猫 说:

错误/Android运行时(18754): android.util.AndroidRuntimeException: 从外部调用startActivity() Activity 上下文需要 FLAG_ACTIVITY_NEW_TASK 标志。这是 真的是你想要的吗?

(整个pastebin上的Logcat

这里是定义活动的清单部分:

<activity android:name=".KeygenAct">
    <intent-filter>
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

整个测试代码(这是我的项目关于找到问题的要点)是在googlecode上找到(http: //code.google.com/p/cleanproject/source/browse/) (Eclipse-Project)

谢谢您的帮助, Esentian

p.s.:keygen不是密钥生成器,它意味着更多的key_general。表达得有点不巧妙;)

I am new at android developing.

The project is about implementing an AbstractAccountAuthenticator with an AbstractThreadedSyncAdapter to sync certain data on a server with a content provider.

I made everything and both adding accounts and syncing is running without any problems.

Now I've tried to add a Preference-Screen just like suggested in the android reference (search for AbstractAccountAuthenticator, it is explained there) via xml like this:

autenticator.xml:

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="typeOfAuthenticator"
    android:icon="@drawable/icon"
    android:smallIcon="@drawable/miniIcon"
    android:label="@string/label"
    android:accountPreferences="@xml/account_preferences"
 />

The Preference-Screen-xml looks like this:

account_preferences.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
 <PreferenceCategory android:title="@string/pref_cat_general">
  <PreferenceScreen android:key="@string/pref_cat_scr_keygen" android:title="@string/pref_cat_scr_keygen_title" android:summary="@string/pref_cat_scr_keygen_summary">
   <intent android:action="android.intent.action.VIEW" android:targetPackage="com.android.clean" android:targetClass="com.android.clean.KeygenAct" />
  </PreferenceScreen>
 </PreferenceCategory>
</PreferenceScreen>

The screen is promted how it should be, but and that is the problem: When I click on the PreferenceScreen with the intent it leads to a crash of the system (both in the emulator and my HTC-Desire).

Logcat says:

ERROR/AndroidRuntime(18754):
android.util.AndroidRuntimeException:
Calling startActivity() from outside
of an Activity context requires the
FLAG_ACTIVITY_NEW_TASK flag. Is this
really what you want?

(whole Logcat on pastebin)

Here the part of the manifest, where the activity is defined:

<activity android:name=".KeygenAct">
    <intent-filter>
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

The whole test-code (it is my project on the essentials to find the problem) is to find at googlecode (http://code.google.com/p/cleanproject/source/browse/) (Eclipse-Project)

Thank you already for your help,
Esentian

p.s.: keygen is not a key generator, it means more key_general. A bit inartfully expressed ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫九 2024-09-26 21:44:33

我遇到了同样的问题,刚刚发现,如果您将首选项更改为:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
 <PreferenceCategory android:title="@string/pref_cat_general">
 </PreferenceCategory>
  <PreferenceScreen android:key="@string/pref_cat_scr_keygen" android:title="@string/pref_cat_scr_keygen_title" android:summary="@string/pref_cat_scr_keygen_summary">
   <intent android:action="android.intent.action.VIEW" android:targetPackage="com.android.clean" android:targetClass="com.android.clean.KeygenAct" />
  </PreferenceScreen>
</PreferenceScreen>

那么它会按预期工作。这很奇怪,因为我希望 PreferenceCategory 将项目分组为其子项...为什么会导致这种不相关的(?)错误?

i had the same problem and have just found out, that if you change your preferences to:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
 <PreferenceCategory android:title="@string/pref_cat_general">
 </PreferenceCategory>
  <PreferenceScreen android:key="@string/pref_cat_scr_keygen" android:title="@string/pref_cat_scr_keygen_title" android:summary="@string/pref_cat_scr_keygen_summary">
   <intent android:action="android.intent.action.VIEW" android:targetPackage="com.android.clean" android:targetClass="com.android.clean.KeygenAct" />
  </PreferenceScreen>
</PreferenceScreen>

Then it works as expected. This is weird because I would expect PreferenceCategory to group items as its children... And why does it result with such unrelated (?) error?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文