Android:启动共享 Intent 会关闭我的 Activity

标签 android android-intent android-fragments android-activity

在我的 fragment 中,当我尝试执行共享 Intent 时,它关闭了我的应用程序。我希望 Intent 出现在我的应用程序之上,当用户完成共享并按下后退按钮时,我希望我的应用程序出现。这是我的 list 文件

    <?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>

这是我的EDITED fragment 中的代码:

@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;
}

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

最佳答案

问题已解决。我在我的 Activity 中有这个,所以当 Intent 弹出时它正在摧毁它。

@Override
protected void onUserLeaveHint()
{
    super.onUserLeaveHint();
    finish();
}

关于Android:启动共享 Intent 会关闭我的 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15172775/

相关文章:

android - 在运行时将 View 添加到 fragment 内的 TableLayout

android - android中的部分粗体字符串

android - 手机摄像头是否有可能以不规则的 fps 拍摄视频?

android - "Permission denied"在我自己的 Activity 中尝试处理来自浏览器的 "Share Image" Intent 时

android - 如何打开图库以选择多个图像?

android - 尽管覆盖了 onSaveInstanceState, fragment 的包在 onCreate 中为 null

java - 为什么这个 fragment 没有得到 bundle ?

javascript - 在ubuntu中为ionic设置环境变量

Android 应用程序因 Intent 而崩溃

java - 动态设置 EditTextPreference 标题