3

在我的片段中,当我尝试共享意图时,午餐会关闭我的应用程序。我希望意图出现在我的应用程序之上,当用户完成共享并按下后退按钮时,我希望我的应用程序出现。这里是我的清单文件Android:开始共享意图关闭我的活动

<?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片段代码:

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

请帮帮忙,我一直在努力与这个用尽一切方法。

+0

为什么你需要内部启动活动:??getActivity()runOnUiThread(新的Runnable() – Gyonder 2013-03-02 09:19:48

+0

其实,真正为什么打开主UI线程的意图这是一个错误,请出示错误logcat显示的你 – IamStalker 2013-03-02 09:34:02

+0

我已经改变了它,你可以看到上面,但同样的问题,意图关闭活动,也没有错误messages.Any想法? – 2013-03-02 09:44:52

回答

0

解决的问题。我在我的活动中有这个,所以当意图弹出时它就会销毁它。

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

标记为接受的答案,以“完成”伫足。 – davidcesarino 2013-03-02 14:40:51

0

注册您在Android电子Mainfest文件共享意向活动和一次检查

<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> 
+0

试过了,同样的问题。这和我的onClick方法有什么区别?他们看起来和我一样。 – 2013-03-02 09:27:51

+0

只是简单的答案,他想提高他的carma :) – IamStalker 2013-03-02 09:31:40