2016-07-27 61 views
1

我使用Intent.createChooser来共享内容。然后共享Intent.createChooser对话框出现并正常工作,但是当我按回按钮关闭对话框时,它完成活动。我想阻止Activity关闭,只想关闭Intent.createChooser对话框。 onclick事件在Recyclerview中。使用Intent.createChooser关闭活动

shareButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       //align the selection to the 
       Intent shareIntent = new Intent(Intent.ACTION_SEND); 
       shareIntent.setType("text/plain"); 
       shareIntent.putExtra(Intent.EXTRA_TEXT, items.get(position).getShareUrl()); 
       context.startActivity(Intent.createChooser(shareIntent, "Share with")); 
      } 
     }); 


<?xml version="1.0" encoding="utf-8"?> 

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="android.permission.CLEAR_APP_CACHE" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
<uses-permission android:name="android.permission.VIBRATE" /> 

<supports-screens> 
    android:resizeable="true" 
    android:smallScreens="true" 
    android:normalScreens="true" 
    android:largeScreens="true" 
    android:xlargeScreens="true" 
    android:anyDensity="true" 
</supports-screens> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity 
     android:name=".MainActivity" 
     android:configChanges="keyboardHidden|orientation|screenSize" 
     android:hardwareAccelerated="true" 
     android:largeHeap="true" 
     android:launchMode="singleTop" 
     android:noHistory="true" 
     android:screenOrientation="portrait" 
     android:showAsAction="ifRoom|withText"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

+0

你可以在这里发布你的完整代码吗? –

+0

@Kishanpatel这是我用来分享点击事件的内容.. –

+0

尝试了你的代码,它并没有关闭原来的活动后点击。显示您的清单文件和完整的原始活动代码。 – Divers

回答

3

在您的清单文件中删除从MainActivity android:noHistory="true"

+0

U很惊人..非常感谢... –