使用Intent.createChooser关闭活动

时间:2016-07-27 07:16:59

标签: android android-activity

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

 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>

1 个答案:

答案 0 :(得分:3)

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