4

在我的片段中,当我尝试分享一个共享意图时,它会关闭我的应用程序。我希望意图出现在我的应用程序顶部,当用户完成共享并按下后退按钮时,我希望我的应用程序出现。这是我的清单文件

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.joyfm.activity"
    android:versionCode="5"
    android:versionName="1.4" >

    <uses-sdk
        android:minSdkVersion="4"
        android:targetSdkVersion="17" />

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

    <application
        android:theme="@style/Theme.Sherlock"
        android:allowBackup="true"
        android:label="@string/app_name"
        android:icon="@drawable/logo_launcher">
        <activity
            android:theme="@style/Theme.Sherlock"
            android:name="com.joyfm.activity.MainActivity"
            android:configChanges="orientation|screenSize|keyboardHidden"
            android:label="@string/app_name" >
        </activity>
         <activity
            android:name="com.joyfm.activity.SplashActivity"
            android:theme="@style/Theme.Sherlock"
            android:launchMode="singleTask"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

这是我编辑片段中的代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    String authorInformation = "<i><BR>" + news.getAuthorInfo() + "<BR>\u00A9 www.myjoyonline.com</i>";

    ScrollView layout = (ScrollView) inflater.inflate(R.layout.news_viewer, container, false);
    TextView title = (TextView) layout.findViewById(R.id.txtTitle);
    TextView summaryDetails = (TextView) layout.findViewById(R.id.summaryDetails);
    TextView date = (TextView) layout.findViewById(R.id.txtNewsDate);
    TextView copyRight = (TextView) layout.findViewById(R.id.txtCopyRight);
    TextView newsDetails = (TextView) layout.findViewById(R.id.txtNewsDetails);
    ImageViewSpinner image = (ImageViewSpinner) layout.findViewById(R.id.thumbNail);

    title.setText(Html.fromHtml(news.getTitle()));
    summaryDetails.setText(Html.fromHtml(ITALIC_START + news.getDescription() + ITALICS_END));
    date.setText(Html.fromHtml(ITALIC_START + news.getDate() + ITALICS_END));
    newsDetails.setText(Html.fromHtml(news.getNewsItem()));
    copyRight.setText(Html.fromHtml(authorInformation));
    if(news.getThumbnailUrl().trim().length() > 0)
    {
        imageDownloader.download(image, news.getThumbnailUrl(), null);
    }else
    {
        image.setVisibility(View.GONE);
    }

    shareContentSubject = title.getText();
    shareContentDetails = newsDetails.getText();
    image.setClickListener(new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {

                try
                {
                    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                     sharingIntent.setType("text/plain");
                     sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, SHARED_SUBJECT + shareContentSubject);
                     sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareContentDetails);
                     startActivity(Intent.createChooser(sharingIntent, "Share with"));          
                }catch(Exception ex)
                {
                    ex.printStackTrace();
                }
        }
    });
    return layout;
}

请帮忙,我一直在努力解决这个问题并尝试了一切。

4

2 回答 2

0

问题解决了。我的活动中有这个,所以当意图弹出时它正在破坏它。

@Override
protected void onUserLeaveHint()
{
    super.onUserLeaveHint();
    finish();
}
于 2013-03-02T14:05:50.603 回答
-1

在 Android Mainfest 文件中为 Share Intent 注册您的 Activity 并检查一次

 <activity
   android:name=".ActivityTest"
   android:label="@string/app_name" >
   <intent-filter>
     <action android:name="android.intent.action.SEND" />      
     <category android:name="android.intent.category.DEFAULT" />
      <data android:mimeType="text/plain" />    
   </intent-filter>
 </activity> 
于 2013-03-02T09:24:18.090 回答