安卓:ShareActionProvider没有历史 [英] Android: ShareActionProvider with no history

查看:253
本文介绍了安卓:ShareActionProvider没有历史的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Android的文件,如果我不希望我的ShareActionProvider坚持共享的历史,我应该叫

According to the Android documentation if I don't want my ShareActionProvider to persist the share history I should call

mShareActionProvider.setShareHistoryFileName(null)

然而,当我这样做,我得到关于选择股票期权以下崩溃:

However when I do this I get the following crash on selecting a share option:

11-15 10:06:34.848: E/AndroidRuntime(22461): java.lang.IllegalStateException: No preceding call to #readHistoricalData
11-15 10:06:34.848: E/AndroidRuntime(22461):    at android.widget.ActivityChooserModel.persistHistoricalDataIfNeeded(ActivityChooserModel.java:573)
11-15 10:06:34.848: E/AndroidRuntime(22461):    at android.widget.ActivityChooserModel.addHisoricalRecord(ActivityChooserModel.java:743)
11-15 10:06:34.848: E/AndroidRuntime(22461):    at android.widget.ActivityChooserModel.chooseActivity(ActivityChooserModel.java:491)
11-15 10:06:34.848: E/AndroidRuntime(22461):    at android.widget.ActivityChooserView$Callbacks.onItemClick(ActivityChooserView.java:547)

下面是code,它设置了ShareActionProvider:

Here is the code that sets up the ShareActionProvider:

public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.article_pager_menu, menu);
    // mShareActionProvider is a field in the Activity
    mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_share)
            .getActionProvider();
    mShareActionProvider
            .setShareHistoryFileName(null);
    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    mShareActionProvider.setShareIntent(shareIntent);
    mShareActionProvider.onCreateActionView();
    return true;
}

任何想法如何,我可以解决这个问题?

Any ideas how I can fix this?

推荐答案

所以,最后我不得不通过复制一个在Android源发现写我自己的ShareActionProvider。我也不得不复制过来的ActivityChooserView和源ActivityChooserModel。隐藏在操作栏上的缺省活动实际需要的修改是在ActivityChooserView的updateAppearance()方法。这是它应该如何看:

So in the end I had to write my own ShareActionProvider by copying the one found in Android source. I also had to copy over the ActivityChooserView and the ActivityChooserModel from source. The actual modification needed to hide the default activity in the action bar is in the updateAppearance() method in the ActivityChooserView. This is how it should look:

private void updateAppearance() {
    // Expand overflow button.
    if (mAdapter.getCount() > 0) {
        mExpandActivityOverflowButton.setEnabled(true);
    } else {
        mExpandActivityOverflowButton.setEnabled(false);
    }
    mDefaultActivityButton.setVisibility(View.GONE);
    if (mDefaultActivityButton.getVisibility() == VISIBLE) {
        mActivityChooserContent.setBackgroundDrawable(mActivityChooserContentBackground);
    } else {
        mActivityChooserContent.setBackgroundDrawable(null);
    }
}

我不明白,为什么setShareHistoryFileName(空)是导致我原来虽然描述的问题。感谢您的企图答案七。

I couldn't figure out why setShareHistoryFileName(null) was causing the problem I originally described though. Thanks for the attempted answer Seven.

这篇关于安卓:ShareActionProvider没有历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆