2016-07-27 62 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很驚人..非常感謝... –