0

这是我的偏好类:

customPref
                .setOnPreferenceClickListener(new OnPreferenceClickListener() {

                    public boolean onPreferenceClick(Preference preference) {

                        Toast.makeText(getBaseContext(),
                                "The custom preference has been clicked",
                                Toast.LENGTH_LONG).show();
                        SharedPreferences customSharedPreference = getSharedPreferences(
                                "myCustomSharedPrefs", Activity.MODE_PRIVATE);
                        SharedPreferences.Editor editor = customSharedPreference
                                .edit();
                        editor.putString("myCustomPref",
                                "The preference has been clicked");
                        editor.commit();
                        return true;
                    }

                });

这能够在 Toast 上显示数据。

但是当我应用此代码时

customPref
            .setOnPreferenceClickListener(new OnPreferenceClickListener() {

                public boolean onPreferenceClick(Preference preference) {

                    Intent int1 = new Intent(getBaseContext(),
                            termandcondition.class);
                    getBaseContext().startActivity(int1);


                    return true;
                }

            });

在首选项中,它变成了错误,现在显示数据请帮助我如何申请去另一个活动

这是 prefnces.xml 文件

<Preference
        android:key="customPref"
        android:summary="END-USER LICENCE AGREEMENT FOR USING WWW.TAXMANN.COM"
        android:title="Term and Condition"



         />

我尝试了很多次现在能够做到请帮助我

4

1 回答 1

0

问题是您使用getBaseContext().startActivity()的是startActivity(). 因此,您尝试从活动上下文之外开始一个新活动。就像错误说的那样:Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? 所以这可能不是你真正想要的。Android 要求您从其他活动中启动活动以维护后台堆栈。

于 2012-12-12T06:44:49.450 回答